Created
April 14, 2020 00:21
-
-
Save Pinacolada64/917d41fe5bad380352d56fbe02351bcf to your computer and use it in GitHub Desktop.
Add random junk to buffers, test compare routines (line 420)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ascii:alt} | |
{number:10} | |
goto {:screen} | |
' init: | |
' TODO: ask from directory or specific track/sector | |
' TODO: output log: screen, printer, disk | |
' input any init: | |
a$="":i%=. | |
' max file entries on a 1541 disk: | |
' sl$=source list, tl$=target list | |
dim sl$(144),tl$(144) | |
{:open_directory} | |
open 2,8,.,"$0:"+pa$ | |
' from lfn#2, get 15 bytes, crskip=0, get dir entry into a$ | |
sys ia,2,16,.,a$ | |
print a$;: | |
' TODO: when changing display/highlight color: | |
' lda colorDisplay | |
' cmp colorBackground | |
' beq chooseAgain ; avoids invisible text | |
{:screen} | |
print"{switchdisable}{lowercase}{clear}":gosub{:sector_frame}:sys{sym:screen_setup}:print:gosub{:sector_frame} | |
' print" Link: 000 Diff: 000000 Bytes: 000000" | |
' ^ 1 ^ 2 ^ | |
' 0123456789abcdef0123456789abcdef0123456 | |
sys{sym:reset_buffers} | |
' sys{sym:incLinkDiffs}:sys{sym:incDiffCount}:sys{sym:incByteCount} | |
sys{sym:add_buffer_junk}:sys{sym:compare_buffers} | |
end | |
' links: max 664 blocks | |
' diffs: max 174848 | |
' bytes: max 174848 per disk | |
{:sector_frame} | |
print"{$c0:40}{down:6}"tab(16)"{176}{$c0:39}{189}" | |
' {:test_fill} | |
' print"{up:8}";:for x=1 to 255:print ".";:next:print | |
return | |
{asm} | |
status = $90 ; serial i/o status | |
string = $f7 ; temp pointer for string address, used by print_at | |
temp = $f9 ; temp pointer for quick zp loops | |
screen = temp ; for print_at routine | |
buffer = $f9 ; does double duty as current buffer address | |
pbuf_orig= $fb ; pointer to original buffer | |
pbuf_diff= $fd ; pointer to difference buffer | |
linprt = $bdcd ; print floating point # in >.a <.x | |
setmsg = $ff90 | |
readst = $ffb7 | |
setlfs = $ffba | |
setnam = $ffbd | |
openf = $ffc0 | |
closef = $ffc3 | |
chkin = $ffc6 | |
chkout = $ffc9 | |
clrchn = $ffcc | |
chrin = $ffcf | |
chrout = $ffd2 | |
loadf = $ffd5 | |
savef = $ffd8 | |
stop = $ffe1 ; .z = 1 if pressed | |
getin = $ffe4 | |
; screen memory | |
text_ram = $0400 | |
; row_* = physical line # on screen within screen/color ram | |
; (add text_ram or color_ram to get final address) | |
row_orig = (40*2) ; 2nd row (80) | |
row_status_line = (40*10) ; 10th row (400) | |
row_diff = (40*12) ; 12th row (480) | |
; since we're using screen ram as buffers, add that constant: | |
buf_orig = text_ram + row_orig ; $0450, 1104 | |
buf_status_line = text_ram + row_status_line ; $0590, 1424 | |
buf_diff = text_ram + row_diff ; $05e0, 1504 | |
; color memory | |
color_ram = $d800 | |
col_orig = color_ram + row_orig ; color for original buffer | |
col_status_line = color_ram + row_status_line ; color for status line | |
col_diff = color_ram + row_diff ; color for difference buffer | |
init: | |
; FIXME - jsr table in rough order of operations | |
jsr >@init | |
jsr set_text_diff | |
jsr >@get_sector | |
jsr set_text_orig | |
; TODO jsr get_sector | |
; TODO jsr >@compare_links | |
jsr compare_buffers | |
; TODO jsr >@logging | |
@init: | |
; set up addresses of i/o buffers for (zp),y addressing | |
; $fa/fb: (buf_curr) (gets loaded with buf_orig at start) | |
; $fc/fd: (original) lda ($fc),y | |
; $fe/ff: (difference) cmp ($fe),y | |
; bne ... | |
; use: ; instead of two disk i/o loops like: | |
; ; and later: | |
; jsr getin ; jsr getin jsr getin | |
; sta (buf_curr),y ; sta ($fc),y sta ($fe),y | |
; iny ; iny iny | |
; bne ... ; bne ... bne ... | |
; hmm | |
screen_setup: | |
lda #<msg_status_line | |
sta string | |
lda #>msg_status_line | |
sta string+1 | |
jsr print_at | |
lda #<msg_info_row0 | |
sta string | |
lda #>msg_info_row0 | |
sta string+1 | |
jsr print_at | |
lda #<msg_info_row1 | |
sta string | |
lda #>msg_info_row1 | |
sta string+1 | |
jsr print_at | |
lda #<msg_info_row2 | |
sta string | |
lda #>msg_info_row2 | |
sta string+1 | |
jsr print_at | |
lda #<msg_info_row3 | |
sta string | |
lda #>msg_info_row3 | |
sta string+1 | |
jsr print_at | |
lda #<msg_info_row4 | |
sta string | |
lda #>msg_info_row4 | |
sta string+1 | |
jsr print_at | |
rts | |
set_text_orig: | |
; point ($f9) to original buffer (text) | |
lda #>buf_orig | |
sta buffer+1 | |
lda #<buf_orig+1 | |
sta buffer | |
rts | |
set_text_diff: | |
; point ($f9) to difference buffer (text) | |
lda #>buf_diff | |
sta buffer+1 | |
lda #<buf_diff+1 | |
sta buffer | |
rts | |
set_col_orig: | |
; point ($f9) to original buffer (color) | |
lda #>col_orig | |
sta buffer+1 | |
lda #<col_orig+1 | |
sta buffer | |
rts | |
set_col_diff: | |
; point ($f9) to original buffer (color) | |
lda #>col_diff | |
sta buffer+1 | |
lda #<col_diff+1 | |
sta buffer | |
rts | |
@get_sector: | |
; fill selected buffer ($f9) with data: | |
; will point to (original) or (difference) | |
jsr getin | |
pha ; save byte | |
lda status ; get i/o status | |
beq >@ | |
; TODO bne disk_error | |
@: | |
pla ; restore byte | |
sta (buffer),y ; put in current buffer | |
iny | |
bne <@get_sector | |
; @swap_buffers: | |
; to swap buffers (i.e., which buffer disk input is filling), load $fa/fb with: | |
; FIXME | |
; lda curr_buf ; low byte of curr_buff | |
; cmp $fc ; orig_buf? | |
; bne ... ; no | |
; cmp $fe ; diff_buf? | |
; bne ... ; no | |
; it really should be one or the other, so if it isn't, set default (maybe on init?) | |
;@: | |
; sta curr_buf | |
reset_buffers: | |
; reset text/color memory for buf_orig and buf_diff to display color to | |
; negate any highlighted diffs on reading a new sector | |
; +2459 | |
; reset buffer text | |
jsr set_text_orig | |
lda #' ' ; fill char | |
jsr reset | |
jsr set_text_diff | |
lda #' ' ; fill char | |
jsr reset | |
; reset buffer colors | |
jsr set_col_orig | |
lda colorDisplay | |
jsr reset | |
jsr set_col_diff | |
lda colorDisplay | |
reset: | |
; clear page ($f9) with .a | |
dec temp ; FIXME: ugly hack to fix off-by-one error when displaying buffers | |
ldy #$00 ; counter | |
@: | |
sta (temp),y ; fill buffer | |
; stx (buffer),y ; valid instruction | |
iny | |
bne <@ | |
rts | |
get_sector: | |
; read sector, display it | |
; supply lfn# in .x | |
; ldx #$03 ;#$03 | |
jsr chkin ;$ffc6 | |
; zero counter: | |
ldy #$00 | |
@: | |
jsr getin ;$ffe4 | |
sta c0f9 ;store byte? | |
jsr getin ;$ffe4 | |
sta byte_in ;$c0fa | |
sta (buffer),y ; store in buffer | |
jsr getin ;$ffe4 | |
sta c0fb ;$c0fb | |
jsr clrchn ;$ffcc | |
jmp * ;$c047 FIXME | |
; &,16,2? reset counters | |
lda #$ff ;#$ff | |
sta c0f9 ;$c0f9 | |
sta byte_in ;$c0fa | |
sta c0fb ;$c0fb | |
; &,16 continued | |
lda #$00 ;#$00 | |
sta c0fc ;$c0fc | |
ldx #$03 ;#$03 | |
jsr chkin ;$ffc6 | |
ldy #$00 ;#$00 | |
ldx #$00 ;#$00 | |
; get byte, put on screen | |
jsr chrin ;$ffcf | |
sta (buffer),y ;fill current buffer | |
iny | |
lda c0f9 ;$c0f9 | |
bne c06c ;$c06c | |
lda byte_in ;$c0fa | |
bne c069 ;$c069 | |
dec c0fb ;$c0fb | |
c069: | |
dec byte_in ;$c0fa | |
c06c: | |
dec c0f9 ;$c0f9 | |
lda c0f9 ;$c0f9 | |
ora byte_in ;$c0fa | |
ora c0fb ;$c0fb | |
c07a: | |
bne c07f ;$c07f | |
inc c0fc ;$c0fc | |
c07f: | |
bne c08a ;$c08a | |
cpy #$fe ;#$fe | |
beq c08a ;$c08a | |
lda status ;$90 | |
beq $c055 ;$c055 | |
inc c0fc ;$c0fc | |
c08a: | |
sty c0f8 | |
jsr clrchn ;$ffcc | |
ldx #$02 ;#$02 | |
jsr chkout ;$ffc9 | |
; read data from screen | |
ldy #$00 ;#$00 | |
@: | |
lda (buffer),y ; get data from current buffer | |
iny | |
; .y=bytes in sector? | |
cpy $c0f8 ;c09e cc f8 c0 $c0f8 | |
bne $c097 ;c0a1 d0 f4 $c097 | |
jsr clrchn ;c0a3 20 cc ff $ffcc | |
; increment on-screen and in-memory byte count | |
jsr incByteCount;c0a6 20 04 c1 $c104 | |
lda $c0fc ;c0a9 ad fc c0 $c0fc | |
beq $c04c ;c0ac f0 9e $c04c | |
rts ;c0ae 60 | |
; TODO: what about file length mismatches | |
; between f1 and f2? | |
; &,16,1 - scan file on lfn#3 (count bytes) | |
ldx #$03 ;c0af a2 03 #$03 | |
jsr chkin ;c0b1 20 c6 ff $ffc6 | |
lda #$00 ;c0b4 a9 00 #$00 | |
sta c0f9 ;c0b6 8d f9 c0 $c0f9 | |
sta byte_in ;c0b9 8d fa c0 $c0fa | |
sta c0fb ;c0bc 8d fb c0 $c0fb | |
c0bf: | |
jsr getin ;c0bf 20 e4 ff $ffe4 | |
inc c0f9 ;c0c2 ee f9 c0 $c0f9 | |
bne c0cf ;c0c5 d0 08 $c0cf | |
inc byte_in ;c0c7 ee fa c0 $c0fa | |
bne c0cf ;c0ca d0 03 $c0cf | |
inc c0fb ;c0cc ee fb c0 $c0fb | |
c0cf: | |
jsr incByteCount;c0cf 20 fd c0 $c0fd | |
jsr stop | |
; bne <blah> ; stop pressed | |
lda status ;c0d2 a5 90 $90 | |
beq c0bf ;c0d4 f0 e9 $c0bf | |
; disk error: | |
ldx #$0f | |
jsr chkin | |
; TODO: get error status message from drive | |
jsr clrchn ;c0d6 20 cc ff $ffcc | |
ldx #$02 ;c0d9 a2 02 #$02 | |
jsr chkout ;c0db 20 c9 ff $ffc9 | |
lda c0f9 ;c0de ad f9 c0 $c0f9 | |
jsr chrout ;c0e1 20 d2 ff $ffd2 | |
lda byte_in ;c0e4 ad fa c0 $c0fa | |
jsr chrout ;c0e7 20 d2 ff $ffd2 | |
lda c0fb ;c0ea ad fb c0 $c0fb | |
jsr chrout ;c0ed 20 d2 ff $ffd2 | |
jsr clrchn ;c0f0 20 cc ff $ffcc | |
lda #$03 ;c0f3 a9 03 #$03 | |
jmp closef ;c0f5 4c c3 ff $ffc3 | |
c0f8: | |
brk | |
; current lfn? | |
c0f9: | |
brk | |
byte_in: | |
brk ;c0fa | |
c0fb: | |
brk ;c0fb | |
bad_byte: | |
c0fc: | |
brk ;c0fc | |
incLinkDiffs: | |
; increment in-memory link diff count: | |
; (for logging) | |
inc link_diffs+1 | |
lda link_diffs+1 | |
bne >@ | |
inc link_diffs | |
; increment on-screen link diff count: | |
@: | |
ldx #$09 ; offset from buf_status_line | |
ldy #$03 ; 3 digits | |
jmp c108 | |
incDiffCount: | |
; increment in-memory byte diff count: | |
; (for logging) | |
inc byte_diffs+1 | |
lda byte_diffs+1 | |
bne >@ | |
inc byte_diffs | |
; increment on-screen byte diff count | |
@: | |
ldx #$17 ;offset from buf_status_line | |
ldy #$06 ;digits | |
jmp c108 ;$c108 | |
incByteCount: | |
; increment on-screen byte count | |
ldx #$26 ;offset from buf_status_line | |
ldy #$06 ;digits | |
c108: | |
inc buf_status_line,x | |
lda buf_status_line,x | |
cmp #$3a ; ':' | |
bne c11b | |
lda #'0' | |
sta buf_status_line,x | |
dex | |
dey | |
bne c108 ;$c108 | |
c11b: | |
rts | |
add_buffer_junk: | |
; add some junk to test compare_buffers | |
lda #$ff ; junk byte to store | |
ldx <@ ; get number of diffs, used as counter | |
ldy <@ ; .y is position in junk_offsets table | |
junk_loop: | |
; get the offsets from the junk_offsets table, | |
; store at offset .y in pbuf_diff buffer, | |
; store at offset .y-1 in pbuf_orig buffer, | |
; dec counter | |
; would this be a good use of lda (pbuf_diff,x)? | |
clc | |
ldx junk_offsets ,x ; get offset from table | |
sta (pbuf_diff) ,y ; store in diff buffer | |
sta ((pbuf_orig)-1),y ; store in orig buffer, offset by -1 | |
; so there's something to diff | |
dey ; dec table position | |
dex ; | |
bne junk_loop | |
rts | |
junk_offsets: | |
; result: 1 link diff, 7 sector byte diffs | |
byte 1,8,16,24,32,64,128,192,255 | |
@: | |
byte <(@-junk_offsets) | |
compare_buffers: | |
ldy #$00 | |
@: | |
lda (pbuf_orig),y; source | |
cmp (pbuf_diff),y; target | |
bne inc_diff | |
iny | |
beq <@ | |
jmp >@ | |
@: | |
rts | |
inc_diff: | |
; peek(sym:diff_count)+256*(peek(sym:diff_count))+1 is the # of differences | |
inc diff_count+1 | |
beq <@ | |
inc diff_count | |
@: | |
; highlight the diff in orig_buf and diff_buf color memory | |
; .y is diff position in either buffer | |
pha ; save comparison char in orig_buf | |
lda colorHighlight | |
sta col_diff,y | |
sta col_orig,y | |
pla ; get comparison char | |
; TODO: add to diff tables | |
lda (pbuf_diff),y | |
; assuming f2 is target to compare f1 against | |
; FIXME: ugh do I need linked lists? diff_count is 16-bit, | |
; can't just do sta diff_count,y -- f1/f2 byte tables will most likely grow >256 bytes, | |
; and what do you do when a table > 1 page? | |
; sta f2,x ; help | |
jsr incDiffCount | |
rts | |
print_at: | |
; gets x/y coords from 1st 2 bytes; | |
; string format is "<x> <y> <text> {0}" | |
; <x y> is row/column to plot string in screen ram | |
; lda (string),y to get byte from string | |
; sta (screen),y to plot to screen_ram | |
; reset (screen) since it's been modified by previous runs | |
lda #<text_ram | |
sta screen | |
lda #>text_ram | |
sta screen+1 | |
ldy #$00 ; reset string pointer | |
; get/set coordinates, get past coordinate bytes | |
; only using zp,y since lda ($xx) is invalid | |
lda (string),y ; 1st byte: x coordinate | |
inc string ; move past x coordinate in string | |
; adjust (screen) address by (40*.a) per row | |
tay ; now .y = how many rows down | |
@: | |
clc | |
lda screen | |
adc #40 ; add each +40 to lsb of (screen) | |
sta screen | |
lda screen+1 | |
adc #$00 | |
sta screen+1 | |
dey | |
bne <@ | |
; working multi-byte add: | |
; clc | |
; lda num1 | |
; adc num2 | |
; sta result_low | |
; lda result_high | |
; adc #$00 | |
; sta result_high | |
; rts | |
@put_y: | |
ldy #0 | |
clc | |
lda screen ; lsb of screen_ram | |
adc (string),y ; 1st byte: y coord | |
sta screen ; add that to screen_ram | |
lda screen+1 | |
adc #$00 | |
sta screen+1 | |
inc string ; 2 bytes into string, should point to string text | |
@: | |
lda (string),y | |
beq >@ ; 0-byte: end of string | |
sta (screen),y ; store on screen | |
iny ; inc pointer | |
jmp <@ | |
@: | |
rts | |
; tables: | |
; colors: | |
colorBackground: | |
byte $08 | |
colorDisplay: | |
byte $01 ; white | |
colorHighlight: | |
byte $02 ; red | |
; strings: | |
sector_frame_top: | |
ascii "{$a0:40}{$00}" | |
sector_frame_bottom: | |
ascii "{176}{$a0:40}{189}{$00}" | |
{alpha:pokealt} | |
; for upper/lowercase strings in screen_ram | |
msg_status_line: | |
; first two bytes: row, col | |
byte $0a,$01 | |
ascii "Link: 000 Diff: 000000 Bytes: 000000{$00}" | |
msg_info_row0: | |
byte $14,$0b | |
ascii "Links Offsets Bytes{$00}" | |
msg_info_row1: | |
byte $15,$02 | |
ascii "Source $th,$sh $ws/$wfhex $h1 {34}s{34}{$00}" | |
msg_info_row2: | |
byte $16,$02 | |
ascii "Target $th,$sh $h2{$00}" | |
msg_info_row3: | |
byte $17,$02 | |
ascii "Source trk,sec d01{$00}" | |
msg_info_row4: | |
byte $18,$02 | |
ascii "Target trk,sec wsd/ wfdec d02 {34}s{34}{$00}" | |
msg_press_any_key: | |
; row, column: | |
byte $00,$0a | |
ascii "Press any key to end{$00}" | |
diff_count: | |
word $0000 | |
link_diffs: | |
word $0000 | |
byte_diffs: | |
word $0000 | |
diff_sectors: | |
byte $00 | |
; Press any key to end | |
; ---------------------------------------- | |
; x....................................... | |
; ........................................ | |
; ........................................ | |
; ........................................ | |
; ........................................ | |
; ........................................ | |
; ...............+------------------------ | |
; ---------------+ filename | |
; Link: 000 Diff: 000000 Bytes: 000000 | |
; ---------------------------------------- | |
; x....................................... | |
; ........................................ | |
; ........................................ | |
; ........................................ | |
; ........................................ | |
; ........................................ | |
; ...............+------------------------ | |
; ---------------+ filename | |
; Links Offsets Bytes | |
; Source $th,$sh $ws/$wfhex $h1 "s" | |
; Target $th,$sh $h2 [offsets not duplicated here | |
; Source trk,sec d01 since they will be the same] | |
; Target trk,sec wsd/ wfdec d02 "s" | |
; source: source file | |
; target: target file | |
; Link | |
; $th: track (hex) [links to next track/sector could differ | |
; $sh: sector (hex) if files are from different disk images] | |
; trk: track (dec) | |
; sec: sector (dec) | |
; Offsets ($02-$ff: track/sector link bytes counted above) | |
; bytes on 1541: 174848 <=> $2ab00 | |
; $ws: within sector (hex, $00-$ff) | |
;$wfhex: within file (hex, $00000-$2ab00) | |
; wsd: within sector (dec, 000-255) | |
; wfdec: within file (dec, 000000-174848) | |
; Byt: $h1/$h2 = file1/2 byte (hex) | |
; d01/d02 = file1/2 byte (dec) | |
; Scn "s"=screen code | |
; (only if output is screen, could result in unprintable | |
; characters if logging to disk or printer) | |
{endasm} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment