May 21 2025 Elf II BASIC/math ROM board, cassette SAVE disassembly Herb Johnson, Marcel von Tongeren, with others ; SEP RE handler for SAVE routine only ; if carry=1 countdown from 07, if carry=0 countdown from 1DH ; short interval 07 is bit 1, long interval 1DH is bit 0 ; Q is set for 07/1D, cleared for 07/1D, then returns ; RD accumulates bit-set count for byte parity R1135 SEP R3 ;1135-D3 ;return to calling code SEQ ;1136-7B ;SEP RE entry, set Q now LDI 01DH ;1137-F8 1D ;if carry=0 1DH, don't bump parity BNF R113E ;1139-3B 3E ; LDI 007H ;113B-F8 07 ;if carry=1 07H, bump RD INC RD ;113D-1D ; accum bit parity R113E STR R2 ;113E-52 ;save 07/1D at R2 addr R113F SMI 001H ;113F-FF 01 ;countdown timing loop BDF R113F ;1141-33 3F BNQ R1135 ;1143-39 35 ;return when Q clear REQ ;1145-7A ;else clear Q now LDN R2 ;1146-02 ;restore countdown BR R113F ;1147-30 3F ;loop once more with Q = 0 ;SAVE Routine S1149 CALL S00A2 ;1149-D4 00 A2 ;RB = BASIC start (0x2006) SEP R7 ;114C-D7 ;Set RD to a pointer to end BASIC (0x..0D) DB 0DH ;114D-0D ;Set stack to RD and increase RD (LDA RD). ; RD is now 0x..0E GLO RB ;114E-8B ;RB to point to BASIC start address SD ;114F-F5 PLO RC ;1150-AC ;RC will be byte counter DEC RD ;1151-2D GHI RB ;1152-9B ;RB is still start address SDB ;1153-75 ADI 001H ;1154-FC 01 PHI RC ;1156-BC ;RC = &RD (end BASIC) - RB (start basic) + 0x100, ; RC used as length byte DEC RB ;1157-2B GLO RC ;1158-8C STR RB ;1159-5B ;Store low byte length on 0x2005 DEC RB ;115A-2B GHI RC ;115B-9C STR RB ;115C-5B ;Store high byte length on 0x2004 GHI R3 ;115D-93 ;set up SEP RE handler PHI RE ;115E-BE ;at this same code-page address INC RC ;115F-1C INC RC ;1160-1C ;RC = RC + 2, the length less the 2 length bytes. LDI 036H ;1161-F8 36 PLO RE ;1163-AE ;RE points to 1136H handler LDI 080H ;1164-F8 80 PHI RD ;1166-BD ;RD.1 counts to 80H=128 decimal R1167 SMI 000H ;1167-FF 00 ;set carry, DF = 1 SEP RE ;1169-DE ;toggle Q based on carry GHI RD ;116A-9D BNZ R1167 ;116B-3A 67 ;loop 128 times. This must be cass leader! ;now send bytes as start/8bits/parity frame ;first point to byte and set up start bit and bit counters R116D SEQ ;116D-7B LDA RB ;116E-4B ;data from addr RB, incr RB PHI RA ;116F-BA ; into RA.1 ADI 000H ;1170-FC 00 ;clear carry start bit, DF = 0 LDI 009H ;1172-F8 09 ;RA.0 as counter from 9 for 10 bit frame PLO RA ;1174-AA PLO RD ;1175-AD ;save 9 in RD.0 also ;loop for start and 8 bits R1176 SEP RE ;1176-DE ;toggle Q by carry, first carry is start bit DEC RA ;1177-2A GLO RA ;1178-8A BZ R1180 ;1179-32 80 ;exit loop at RA=0000 GHI RA ;117B-9A ;get data byte SHL ;117C-FE ;shift MSB into carry PHI RA ;117D-BA ;save result BR R1176 ;117E-30 76 ;and toggle Q with carry ;send parity bit R1180 GLO RD ;1180-8D ;get SEP RE parity value SHR ;1181-F6 ;shift LSB into carry SEP RE ;1182-DE ;toggle Q as parity bit DEC RC ;1183-2C ;count down on bytes to send GHI RC ;1184-9C ;count doesn't go negative, ; due to the addition of 0x100 earlier. ;when RC.1 = 0 we are done. BNZ R116D ;1185-3A 6D ;if more bytes send next byte ;all bytes sent, carry now zero SEP RE ;1187-DE ;4 bits of zero carry SEP RE ;1188-DE SEP RE ;1189-DE SEP RE ;118A-DE LDI 0FFH ;118B-F8 FF ;flag as done and return from SAVE RETN ;118D-D5 SEP R5