fix some bugs in pack_word
This commit is contained in:
1 parent
9eb16b5795
commit
bd608b5592
3 files changed
+67
-31
No files matched your search
@@ -37,12 +37,11 @@ got_line_of_input:
|
|||||||
jsr pack_word
|
jsr pack_word
|
||||||
|
|
||||||
;; Print the packed word
|
;; Print the packed word
|
||||||
ldx tokenise_work2
|
lda #<$0100
|
||||||
dex
|
sta temp_string_ptr+0
|
||||||
* lda $0100,x
|
lda #>$0100
|
||||||
sta $0608,x
|
sta temp_string_ptr+1
|
||||||
dex
|
jsr print_packed_string
|
||||||
bpl -
|
|
||||||
|
|
||||||
jsr ready_message
|
jsr ready_message
|
||||||
|
|
||||||
|
|||||||
+60
-25
@@ -56,44 +56,70 @@ pack_char_loop:
|
|||||||
cpx tokenise_work1
|
cpx tokenise_work1
|
||||||
beq at_end
|
beq at_end
|
||||||
lda #$FF
|
lda #$FF
|
||||||
at_end: .byte $2C
|
.byte $2C
|
||||||
LDA #$FE
|
at_end: LDA #$FE
|
||||||
dex
|
dex
|
||||||
ldy tokenise_work2
|
jsr write_unpacked_char
|
||||||
sta $0100,y
|
|
||||||
inc tokenise_work2
|
|
||||||
|
|
||||||
jmp output_exception_byte
|
output_exception_byte:
|
||||||
|
lda $0200,x
|
||||||
|
jsr write_unpacked_char
|
||||||
|
jmp consider_next_char
|
||||||
|
|
||||||
have_nybl_before_exception_char:
|
have_nybl_before_exception_char:
|
||||||
;; Or existing byte with #$0F, and clear nybl flag
|
;; Or existing byte with #$0F, and clear nybl flag
|
||||||
ldy tokenise_work2
|
ldy tokenise_work2
|
||||||
dey
|
|
||||||
lda $0100,y
|
lda $0100,y
|
||||||
ora #$0f
|
ora #$0f
|
||||||
sta $0100,y
|
sta $0100,y
|
||||||
|
inc tokenise_work2
|
||||||
|
|
||||||
|
;; FALL THROUGH
|
||||||
|
|
||||||
|
write_literal_and_terminate_if_required:
|
||||||
;; Clear have nybl flag
|
;; Clear have nybl flag
|
||||||
lda #$00
|
lda #$00
|
||||||
sta tokenise_work3
|
sta tokenise_work3
|
||||||
|
|
||||||
;; FAll through
|
|
||||||
|
|
||||||
output_exception_byte:
|
|
||||||
ldy tokenise_work2
|
|
||||||
lda $0200,x
|
lda $0200,x
|
||||||
|
jsr write_unpacked_char
|
||||||
|
jsr output_exception_byte
|
||||||
|
jsr end_string_if_required
|
||||||
|
|
||||||
|
end_string_if_required:
|
||||||
|
;; Check if X points to last char of string to be packed
|
||||||
|
inx
|
||||||
|
cpx tokenise_work1
|
||||||
|
beq +
|
||||||
|
dex
|
||||||
|
rts
|
||||||
|
*
|
||||||
|
dex
|
||||||
|
;; Fall through
|
||||||
|
|
||||||
|
end_string:
|
||||||
|
;; Write end of string sequence if required
|
||||||
|
inc $d020
|
||||||
|
lda #$00
|
||||||
|
jsr write_unpacked_char
|
||||||
|
rts
|
||||||
|
|
||||||
|
write_unpacked_char:
|
||||||
|
ldy tokenise_work2
|
||||||
sta $0100,y
|
sta $0100,y
|
||||||
iny
|
iny
|
||||||
sty tokenise_work2
|
sty tokenise_work2
|
||||||
jmp consider_next_char
|
rts
|
||||||
|
|
||||||
not_exception_char:
|
not_exception_char:
|
||||||
;; It wasn't an exception char, so write the symbol out
|
;; It wasn't an exception char, so write the symbol out
|
||||||
cmp #$10
|
cmp #$10
|
||||||
bcs whole_byte_symbol
|
bcs whole_byte_symbol
|
||||||
;; Nybl value
|
|
||||||
|
;; Nybl encoded value: Put in upper half or lower half of a byte?
|
||||||
ldy tokenise_work3
|
ldy tokenise_work3
|
||||||
bne store_low_nybl
|
bne store_low_nybl
|
||||||
|
|
||||||
;; Store in high nybl -- so shift it into the hi nybl
|
;; Store in high nybl -- so shift it into the hi nybl
|
||||||
asl
|
asl
|
||||||
asl
|
asl
|
||||||
@@ -104,41 +130,49 @@ not_exception_char:
|
|||||||
bne stored_nybl ; Must be taken, as A cannot be $00
|
bne stored_nybl ; Must be taken, as A cannot be $00
|
||||||
|
|
||||||
store_low_nybl:
|
store_low_nybl:
|
||||||
|
;; Low nybl gets added to high nybl already stored in the byte
|
||||||
ldy tokenise_work2
|
ldy tokenise_work2
|
||||||
ora $0100,y
|
ora $0100,y
|
||||||
sta $0100,y
|
sta $0100,y
|
||||||
|
|
||||||
stored_nybl:
|
stored_nybl:
|
||||||
;; Now toggle the nybl flag
|
;; Now toggle the nybl flag
|
||||||
lda tokenise_work3
|
lda tokenise_work3
|
||||||
eor #$ff
|
eor #$ff
|
||||||
sta tokenise_work3
|
sta tokenise_work3
|
||||||
;; And advance the offset if required
|
;; And advance the offset if we filled this byte up
|
||||||
bne consider_next_char
|
bne consider_next_char ; Taken if byte has a nybl free, i.e., don't advance pointer while half byte remains free
|
||||||
|
|
||||||
|
;; Count the filled up byte
|
||||||
inc tokenise_work2
|
inc tokenise_work2
|
||||||
|
|
||||||
|
;; Add termination byte if required
|
||||||
|
;; (This re-writes the same byte again, which we don't care about
|
||||||
|
jsr end_string_if_required
|
||||||
|
|
||||||
jmp consider_next_char
|
jmp consider_next_char
|
||||||
|
|
||||||
whole_byte_symbol:
|
whole_byte_symbol:
|
||||||
|
;; It's a $Fx symbol.
|
||||||
|
;; But if we have a nybl to flush, then we handle it like
|
||||||
|
;; a full exception character
|
||||||
|
|
||||||
ldy tokenise_work3
|
ldy tokenise_work3
|
||||||
beq nothing_to_flush
|
beq nothing_to_flush
|
||||||
|
|
||||||
;; Set low nybl to $F to mark next byte as literal
|
;; Set low nybl to $F to mark next byte as literal
|
||||||
ldy tokenise_work2
|
ldy tokenise_work2
|
||||||
lda $0100,y
|
lda $0100,y
|
||||||
ora #$0f
|
ora #$0f
|
||||||
sta $0100,y
|
sta $0100,y
|
||||||
inc tokenise_work2
|
inc tokenise_work2
|
||||||
;; Clear nybl flag
|
|
||||||
lda #$00
|
jmp write_literal_and_terminate_if_required
|
||||||
sta tokenise_work3
|
|
||||||
;; Load literal byte for storing in output
|
|
||||||
lda $0200,x
|
|
||||||
;; FALL THROUGH
|
|
||||||
|
|
||||||
nothing_to_flush:
|
nothing_to_flush:
|
||||||
;; Write the symbol as it is, or the literal
|
;; Write the symbol as it is, or the literal
|
||||||
;; if it has been passed to us via fall-through
|
;; if it has been passed to us via fall-through
|
||||||
ldy tokenise_work2
|
jsr write_unpacked_char
|
||||||
sta $0100,y
|
|
||||||
inc tokenise_work2
|
|
||||||
|
|
||||||
;; Fall through
|
;; Fall through
|
||||||
|
|
||||||
@@ -160,6 +194,7 @@ consider_next_char:
|
|||||||
;; Last byte was full, so we need at $00 on the end
|
;; Last byte was full, so we need at $00 on the end
|
||||||
;; (unless a $FE token was written 2 bytes ago)
|
;; (unless a $FE token was written 2 bytes ago)
|
||||||
ldy tokenise_work2
|
ldy tokenise_work2
|
||||||
|
iny
|
||||||
lda #$00
|
lda #$00
|
||||||
sta $0100,y
|
sta $0100,y
|
||||||
inc tokenise_work2
|
inc tokenise_work2
|
||||||
@@ -194,7 +229,7 @@ not_nybl_char:
|
|||||||
;; we need to add $E2
|
;; we need to add $E2
|
||||||
tya
|
tya
|
||||||
clc
|
clc
|
||||||
adc #$E2
|
adc #$E3
|
||||||
rts
|
rts
|
||||||
|
|
||||||
not_a_match:
|
not_a_match:
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ found_packed_word:
|
|||||||
lda temp_string_ptr+1
|
lda temp_string_ptr+1
|
||||||
adc #$00
|
adc #$00
|
||||||
sta temp_string_ptr+1
|
sta temp_string_ptr+1
|
||||||
|
|
||||||
|
print_packed_string:
|
||||||
ldy #$ff
|
ldy #$ff
|
||||||
|
|
||||||
next_packed_word_char:
|
next_packed_word_char:
|
||||||
|
|||||||
Reference in new issue
Block a user