; EQU:
; Data addresses used by the opcodes that point to uninitialized memory areas.
; --------------------------------------------------------------
; I/O Port Definitions (from SVI-328 / SV-608M port map)
; --------------------------------------------------------------

; SV-608M SASI Host Adapter
SV608M_RESET    equ  40h    ; W: SASI bus reset
SV608M_DATA_OUT equ  41h    ; W: SASI data bus write (auto-ACK)
SV608M_DATA_IN  equ  42h    ; R: SASI data bus read (auto-ACK)
SV608M_SEL      equ  43h    ; W: SEL signal assertion
SV608M_STATUS   equ  46h    ; R: SASI bus status (MSG·I/O·C/D·REQ·BSY)

; --------------------------------------------------------------

SUB01:       equ  0000h	; 0. Subroutine. Called by: LBL1[015Ch].
DATA1:       equ  0001h	; 1. Data accessed by: 015Fh(in SUB03), 0190h(in SUB03)
SUB02:       equ  0005h	; 5. Subroutine. Called by: LBL1[0105h], LBL1[010Dh], SUB04[0297h], LBL1[013Ch], SUB05[02A3h], SUB08[0311h], LBL1[0159h], SUB25[0412h], SUB03[01A6h], SUB03[01C9h], SUB26[041Eh], SUB27[042Ah], SUB03[021Dh], SUB03[0240h], SUB03[0215h], SUB03[028Ch].
DATA5:       equ  0A0Dh	; 2573. Data accessed by: 06CFh(in SUB28)
; Last element of stack:
DATA6:       equ  201Eh
DATA7:       equ  2420h	; 9248. Data accessed by: 06A2h(in SUB28)


             org 0100h; 0100h


; Label not accessed.
0100 LBL1:
0100              ld   de,0431h 	; 1073
0103              ld   c,09h  	; 9
0105              call SUB02  	; 0005h
0108 .lbl1_loop1:
0108              ld   de,0452h 	; 1106
010B              ld   c,09h  	; 9
010D              call SUB02  	; 0005h
0110 .lbl1_loop2:
0110              call SUB04  	; 0293h
0113              cp   48h    	; 72, 'H'
0115              jp   z,.lbl1_l2 	; 012Eh
0118              cp   46h    	; 70, 'F'
011A              jp   z,.lbl1_l1 	; 0125h
011D              cp   0Dh    	; 13
011F              jp   z,.lbl1_l3 	; 0137h
0122              jp   .lbl1_loop2 	; 0110h
0125 .lbl1_l1:
0125              call SUB05  	; 029Fh
0128              call SUB03  	; 015Fh
012B              jp   .lbl1_loop1 	; 0108h
012E .lbl1_l2:
012E              call SUB05  	; 029Fh
0131              call SUB08  	; 02BCh
0134              jp   .lbl1_loop1 	; 0108h
0137 .lbl1_l3:
0137              ld   de,0625h 	; 1573
013A              ld   c,09h  	; 9
013C              call SUB02  	; 0005h
013F .lbl1_loop3:
013F              call SUB04  	; 0293h
0142              cp   0Dh    	; 13
0144              jp   z,.lbl1_l4 	; 0154h
0147              cp   03h    	; 3
0149              jp   z,.lbl1_l4 	; 0154h
014C              ld   a,07h  	; 7
014E              call SUB05  	; 029Fh
0151              jp   .lbl1_loop3 	; 013Fh
0154 .lbl1_l4:
0154              ld   de,0670h 	; 1648
0157              ld   c,09h  	; 9
0159              call SUB02  	; 0005h
015C              jp   SUB01  	; 0000h


; Subroutine: Size=308, CC=10.
; Called by: LBL1[0128h].
; Calls: SUB02, SUB04, SUB05, SUB06, SUB07, SUB28.
015F SUB03:
015F              ld   hl,(DATA1) 	; 0001h
0162              ld   de,0018h 	; 24
0165              add  hl,de  
0166              ld   (SELF_MOD1),hl 	; 0675h, WARNING: Instruction accesses code!
0169              ld   a,C3h  	; 195,  -61
016B              ld   (SUB28),a 	; 0674h, WARNING: Instruction accesses code!
016E              ld   c,00h  	; 0
0170              call SUB28  	; 0674h
0173              ld   de,000Ah 	; 10
0176              add  hl,de  
0177              ld   c,(hl) 
0178              inc  hl     
0179              ld   b,(hl) 
017A              ld   a,(bc) 
017B              cp   22h    	; 34, '"'
017D              jp   z,.sub03_l1 	; 0188h
0180              ld   a,45h  	; 69, 'E'
0182              ld   (DATA4),a 	; 0673h
0185              jp   .sub03_l2 	; 0190h
0188 .sub03_l1:
0188              ld   a,41h  	; 65, 'A'
018A              ld   (DATA4),a 	; 0673h
018D              jp   .sub03_l2 	; 0190h
0190 .sub03_l2:
0190              ld   hl,(DATA1) 	; 0001h
0193              ld   de,0051h 	; 81
0196              add  hl,de  
0197              ld   (SUB06+1),hl 	; 02A9h, WARNING: Instruction accesses code!
019A              ld   de,0003h 	; 3
019D              add  hl,de  
019E              ld   (SUB07+1),hl 	; 02B3h, WARNING: Instruction accesses code!
01A1              ld   de,04BCh 	; 1212
01A4              ld   c,09h  	; 9
01A6              call SUB02  	; 0005h
01A9 .sub03_loop1:
01A9              call SUB04  	; 0293h
01AC              cp   03h    	; 3
01AE              jp   z,.sub03_loop3 	; 0218h
01B1              cp   0Dh    	; 13
01B3              jp   nz,.sub03_loop1 	; 01A9h
01B6              ld   a,(DATA4) 	; 0673h
01B9              call SUB05  	; 029Fh
01BC              ld   (DATA2),a 	; 051Dh
01BF              sub  41h    	; 65, 'A'
01C1              ld   (SELF_MOD2+2),a 	; 02AFh, WARNING: Instruction accesses code!
01C4              ld   de,0511h 	; 1297
01C7              ld   c,09h  	; 9
01C9              call SUB02  	; 0005h
01CC .sub03_loop2:
01CC              call SUB04  	; 0293h
01CF              cp   0Dh    	; 13
01D1              jp   z,.sub03_l3 	; 01E1h
01D4              cp   03h    	; 3
01D6              jp   z,.sub03_l5 	; 0292h
01D9              ld   a,07h  	; 7
01DB              call SUB05  	; 029Fh
01DE              jp   .sub03_loop2 	; 01CCh
01E1 .sub03_l3:
01E1              call SUB06  	; 02A8h
01E4              ld   hl,4000h 	; 16384
01E7              ld   de,0900h 	; 2304
01EA              ld   bc,0080h 	; 128
01ED              ldir        
01EF              ld   hl,5500h 	; 21760
01F2              ld   de,0980h 	; 2432
01F5              ld   bc,0800h 	; 2048
01F8              ldir        
01FA              ld   hl,5D00h 	; 23808
01FD              ld   de,1180h 	; 4480
0200              ld   bc,0E00h 	; 3584
0203              ldir        
0205              ld   hl,4080h 	; 16512
0208              ld   de,1F80h 	; 8064
020B              ld   bc,1480h 	; 5248
020E              ldir        
0210              ld   de,0534h 	; 1332
0213              ld   c,09h  	; 9
0215              call SUB02  	; 0005h
0218 .sub03_loop3:
0218              ld   de,05A4h 	; 1444
021B              ld   c,09h  	; 9
021D              call SUB02  	; 0005h
0220 .sub03_loop4:
0220              call SUB04  	; 0293h
0223              cp   03h    	; 3
0225              jp   z,.sub03_l5 	; 0292h
0228              cp   0Dh    	; 13
022A              jp   nz,.sub03_loop4 	; 0220h
022D              ld   a,(DATA4) 	; 0673h
0230              call SUB05  	; 029Fh
0233              ld   (DATA3),a 	; 060Eh
0236              sub  41h    	; 65, 'A'
0238              ld   (SELF_MOD3+2),a 	; 02B9h, WARNING: Instruction accesses code!
023B              ld   de,05FDh 	; 1533
023E              ld   c,09h  	; 9
0240              call SUB02  	; 0005h
0243 .sub03_loop5:
0243              call SUB04  	; 0293h
0246              cp   0Dh    	; 13
0248              jp   z,.sub03_l4 	; 0258h
024B              cp   03h    	; 3
024D              jp   z,.sub03_l5 	; 0292h
0250              ld   a,07h  	; 7
0252              call SUB05  	; 029Fh
0255              jp   .sub03_loop5 	; 0243h
0258 .sub03_l4:
0258              ld   hl,0900h 	; 2304
025B              ld   de,4000h 	; 16384
025E              ld   bc,0080h 	; 128
0261              ldir        
0263              ld   hl,0980h 	; 2432
0266              ld   de,5500h 	; 21760
0269              ld   bc,0800h 	; 2048
026C              ldir        
026E              ld   hl,1180h 	; 4480
0271              ld   de,5D00h 	; 23808
0274              ld   bc,0E00h 	; 3584
0277              ldir        
0279              ld   hl,1F80h 	; 8064
027C              ld   de,4080h 	; 16512
027F              ld   bc,1480h 	; 5248
0282              ldir        
0284              call SUB07  	; 02B2h
0287              ld   de,0534h 	; 1332
028A              ld   c,09h  	; 9
028C              call SUB02  	; 0005h
028F              jp   .sub03_loop3 	; 0218h
0292 .sub03_l5:
0292              ret         


; Subroutine: Size=12, CC=2.
; Called by: LBL1[0110h], LBL1[013Fh], SUB03[01A9h], SUB03[01CCh], SUB03[0220h], SUB03[0243h].
; Calls: SUB02.
0293 SUB04:
0293              ld   e,FFh  	; 255,   -1
0295              ld   c,06h  	; 6
0297              call SUB02  	; 0005h
029A              or   a      
029B              jp   z,SUB04 	; 0293h
029E              ret         


; Subroutine: Size=9, CC=1.
; Called by: LBL1[012Eh], LBL1[0125h], LBL1[014Eh], SUB03[01B9h], SUB03[01DBh], SUB03[0230h], SUB03[0252h].
; Calls: SUB02.
029F SUB05:
029F              push af     
02A0              ld   e,a    
02A1              ld   c,02h  	; 2
02A3              call SUB02  	; 0005h
02A6              pop  af     
02A7              ret         


; Subroutine: Size=10, CC=1.
; Called by: SUB03[01E1h], SUB03[0197h].
; Calls: -
02A8 SUB06:
02A8              call SUB06  	; 02A8h
02AB              nop         
02AC              ld   b,b    


; Data accessed by:
; 01C1h(in SUB03)
02AD SELF_MOD2:
02AD              ld   bc,0000h 	; 0
02B0              inc  (hl)   
02B1              ret         


; Subroutine: Size=10, CC=1.
; Called by: SUB03[0284h], SUB03[019Eh].
; Calls: -
02B2 SUB07:
02B2              call SUB07  	; 02B2h
02B5              nop         
02B6              ld   b,b    


; Data accessed by:
; 0238h(in SUB03)
02B7 SELF_MOD3:
02B7              ld   bc,0000h 	; 0
02BA              inc  (hl)   
02BB              ret         


; Subroutine: Size=89, CC=10.
; Called by: LBL1[0131h].
; Calls: SUB02, SUB09, SUB10, SUB11, SUB12, SUB13, SUB15, SUB16, SUB17, SUB25.
02BC SUB08:
02BC              ld   a,00h  	; 0
02BE              ld   hl,0677h 	; 1655
02C1              ld   (hl),a 
02C2              ld   hl,0683h 	; 1667
02C5              ld   b,1Eh  	; 30
02C7 .sub08_loop1:
02C7              ld   (hl),a 
02C8              inc  hl     
02C9              dec  b      
02CA              jp   nz,.sub08_loop1 	; 02C7h
02CD              ld   de,0677h 	; 1655
02D0              call SUB25  	; 040Dh
02D3              cp   FFh    	; 255,   -1
02D5              jp   z,.sub08_l 	; 02FBh
02D8              call SUB16  	; 0366h
02DB              ld   b,62h  	; 98, 'b'
02DD              ld   hl,0900h 	; 2304
02E0              ld   de,0080h 	; 128
02E3 .sub08_loop2:
02E3              call SUB13  	; 0325h
02E6              cp   01h    	; 1
02E8              jp   z,.sub08_l 	; 02FBh
02EB              add  hl,de  
02EC              dec  b      
02ED              jp   nz,.sub08_loop2 	; 02E3h
02F0              call SUB15  	; 033Dh
02F3              cp   00h    	; 0
02F5              jp   nz,.sub08_l 	; 02FBh
02F8              call SUB17  	; 0372h
02FB .sub08_l:
02FB              cp   FFh    	; 255,   -1
02FD              call z,SUB09 	; 0315h
0300              cp   01h    	; 1
0302              call z,SUB10 	; 0319h
0305              cp   02h    	; 2
0307              call z,SUB11 	; 031Dh
030A              cp   00h    	; 0
030C              call z,SUB12 	; 0321h
030F              ld   c,09h  	; 9
0311              call SUB02  	; 0005h
0314              ret         


; Subroutine: Size=4, CC=1.
; Called by: SUB08[02FDh].
; Calls: -
0315 SUB09:
0315              ld   de,0549h 	; 1353
0318              ret         


; Subroutine: Size=4, CC=1.
; Called by: SUB08[0302h].
; Calls: -
0319 SUB10:
0319              ld   de,0569h 	; 1385
031C              ret         


; Subroutine: Size=4, CC=1.
; Called by: SUB08[0307h].
; Calls: -
031D SUB11:
031D              ld   de,0589h 	; 1417
0320              ret         


; Subroutine: Size=4, CC=1.
; Called by: SUB08[030Ch].
; Calls: -
0321 SUB12:
0321              ld   de,0534h 	; 1332
0324              ret         


; Subroutine: Size=21, CC=2.
; Called by: SUB08[02E3h].
; Calls: SUB14, SUB26, SUB27.
0325 SUB13:
0325              push hl     
0326              push de     
0327              push hl     
0328              pop  de     
0329              call SUB26  	; 0419h
032C              ld   de,0677h 	; 1655
032F              call SUB27  	; 0425h
0332              cp   00h    	; 0
0334              call nz,SUB14 	; 033Ah
0337              pop  de     
0338              pop  hl     
0339              ret         


; Subroutine: Size=3, CC=1.
; Called by: SUB13[0334h].
; Calls: -
033A SUB14:
033A              ld   a,01h  	; 1
033C              ret         


; Subroutine: Size=41, CC=3.
; Called by: SUB08[02F0h].
; Calls: SUB16.
033D SUB15:
033D              call SUB16  	; 0366h
0340              in   a,(SV608M_STATUS) 	; 70
0342              and  20h    	; 32, ' '
0344              cp   20h    	; 32, ' '
0346              jp   z,.sub15_l1 	; 034Ch
0349              ld   a,02h  	; 2
034B              ret         
034C .sub15_l1:
034C              ld   a,01h  	; 1
034E              out  (SV608M_DATA_OUT),a 	; 65
0350              out  (SV608M_SEL),a 	; 67
0352              nop         
0353              nop         
0354              in   a,(SV608M_STATUS) 	; 70
0356              and  02h    	; 2
0358              cp   02h    	; 2
035A              jp   z,.sub15_l2 	; 0360h
035D              ld   a,02h  	; 2
035F              ret         
0360 .sub15_l2:
0360              call SUB16  	; 0366h
0363              ld   a,00h  	; 0
0365              ret         


; Subroutine: Size=12, CC=2.
; Called by: SUB08[02D8h], SUB15[033Dh], SUB15[0360h].
; Calls: -
0366 SUB16:
0366              out  (SV608M_RESET),a 	; 64
0368              push bc     
0369              ld   b,3Ch  	; 60, '<'
036B .sub16_loop:
036B              nop         
036C              dec  b      
036D              jp   nz,.sub16_loop 	; 036Bh
0370              pop  bc     
0371              ret         


; Subroutine: Size=18, CC=1.
; Called by: SUB08[02F8h].
; Calls: SUB18, SUB19, SUB20, SUB22, SUB23.
0372 SUB17:
0372              call SUB18  	; 0384h
0375              call SUB19  	; 0396h
0378              call SUB20  	; 03B7h
037B              call SUB22  	; 03E5h
037E              call SUB23  	; 03F1h
0381              and  02h    	; 2
0383              ret         


; Subroutine: Size=18, CC=2.
; Called by: SUB17[0372h].
; Calls: -
0384 SUB18:
0384              push af     
0385 .sub18_loop:
0385              in   a,(SV608M_STATUS) 	; 70
0387              and  1Fh    	; 31
0389              cp   00h    	; 0
038B              jp   nz,.sub18_loop 	; 0385h
038E              ld   a,01h  	; 1
0390              out  (SV608M_DATA_OUT),a 	; 65
0392              out  (SV608M_SEL),a 	; 67
0394              pop  af     
0395              ret         


; Subroutine: Size=33, CC=1.
; Called by: SUB17[0375h].
; Calls: SUB24.
0396 SUB19:
0396              push af     
0397              ld   a,0Ah  	; 10
0399              call SUB24  	; 03FFh
039C              ld   a,00h  	; 0
039E              call SUB24  	; 03FFh
03A1              ld   a,00h  	; 0
03A3              call SUB24  	; 03FFh
03A6              ld   a,00h  	; 0
03A8              call SUB24  	; 03FFh
03AB              ld   a,31h  	; 49, '1'
03AD              call SUB24  	; 03FFh
03B0              ld   a,07h  	; 7
03B2              call SUB24  	; 03FFh
03B5              pop  af     
03B6              ret         


; Subroutine: Size=36, CC=3.
; Called by: SUB17[0378h].
; Calls: SUB21.
03B7 SUB20:
03B7              push hl     
03B8              push bc     
03B9              push af     
03BA              push de     
03BB              ld   d,31h  	; 49, '1'
03BD              ld   hl,0900h 	; 2304
03C0 .sub20_loop:
03C0              call SUB21  	; 03DBh
03C3              in   a,(SV608M_STATUS) 	; 70
03C5              and  1Fh    	; 31
03C7              cp   1Bh    	; 27
03C9              jp   z,.sub20_l 	; 03D6h
03CC              ld   c,41h  	; 65, 'A'
03CE              ld   b,00h  	; 0
03D0              outir       
03D2              dec  d      
03D3              jp   nz,.sub20_loop 	; 03C0h
03D6 .sub20_l:
03D6              pop  de     
03D7              pop  af     
03D8              pop  bc     
03D9              pop  hl     
03DA              ret         


; Subroutine: Size=10, CC=2.
; Called by: SUB20[03C0h].
; Calls: -
03DB SUB21:
03DB              in   a,(SV608M_STATUS) 	; 70
03DD              and  01h    	; 1
03DF              cp   01h    	; 1
03E1              jp   nz,SUB21 	; 03DBh
03E4              ret         


; Subroutine: Size=12, CC=2.
; Called by: SUB17[037Bh].
; Calls: -
03E5 SUB22:
03E5              in   a,(SV608M_STATUS) 	; 70
03E7              and  1Fh    	; 31
03E9              cp   1Bh    	; 27
03EB              jp   nz,SUB22 	; 03E5h
03EE              in   a,(SV608M_DATA_IN) 	; 66
03F0              ret         


; Subroutine: Size=14, CC=2.
; Called by: SUB17[037Eh].
; Calls: -
03F1 SUB23:
03F1              push af     
03F2 .sub23_loop:
03F2              in   a,(SV608M_STATUS) 	; 70
03F4              and  1Fh    	; 31
03F6              cp   1Fh    	; 31
03F8              jp   nz,.sub23_loop 	; 03F2h
03FB              in   a,(SV608M_DATA_IN) 	; 66
03FD              pop  af     
03FE              ret         


; Subroutine: Size=14, CC=2.
; Called by: SUB19[0399h], SUB19[039Eh], SUB19[03A3h], SUB19[03A8h], SUB19[03ADh], SUB19[03B2h].
; Calls: -
03FF SUB24:
03FF              push af     
0400 .sub24_loop:
0400              in   a,(SV608M_STATUS) 	; 70
0402              and  1Fh    	; 31
0404              cp   0Bh    	; 11
0406              jp   nz,.sub24_loop 	; 0400h
0409              pop  af     
040A              out  (SV608M_DATA_OUT),a 	; 65
040C              ret         


; Subroutine: Size=12, CC=1.
; Called by: SUB08[02D0h].
; Calls: SUB02.
040D SUB25:
040D              push de     
040E              push bc     
040F              push hl     
0410              ld   c,0Fh  	; 15
0412              call SUB02  	; 0005h
0415              pop  hl     
0416              pop  bc     
0417              pop  de     
0418              ret         


; Subroutine: Size=12, CC=1.
; Called by: SUB13[0329h].
; Calls: SUB02.
0419 SUB26:
0419              push bc     
041A              push de     
041B              push hl     
041C              ld   c,1Ah  	; 26
041E              call SUB02  	; 0005h
0421              pop  hl     
0422              pop  de     
0423              pop  bc     
0424              ret         


; Subroutine: Size=12, CC=1.
; Called by: SUB13[032Fh].
; Calls: SUB02.
0425 SUB27:
0425              push bc     
0426              push de     
0427              push hl     
0428              ld   c,14h  	; 20
042A              call SUB02  	; 0005h
042D              pop  hl     
042E              pop  de     
042F              pop  bc     
0430              ret         


0431              defb 0Ch    	; 12

; --------------------------------------------------------------
; String / data region
; --------------------------------------------------------------
0432              defb "608M System Generation Program $", 0Dh, 0Ah, 0Ah
0455              defb "Press ", 22h, "H", 22h, " for Hard disk generation or", 0Dh, 0Ah
047C              defb "      ", 22h, "F", 22h, " for Floppy disk generation or", 0Dh, 0Ah
04A5              defb "      ENTER to exit): $", 0Dh, 0Ah, 0Ah
04BF              defb "Insert Source disk on the floppy drive and ", 0Dh, 0Ah
04EC              defb " press ENTER or Control-C to skip): $", 0Dh, 0Ah
0513              defb "Source on *:, then press ENTER: $", 0Dh, 0Ah
0536              defb "Function complete.$", 0Dh, 0Ah
054B              defb "File T0T1.SYS was not found? $", 0Dh, 0Ah
056B              defb "File T0T1.SYS was corrupted? $", 0Dh, 0Ah
058B              defb "Hard disk write error ! $", 0Dh, 0Ah, 0Ah
05A7              defb "Insert Destination disk on the floppy drive", 0Dh, 0Ah
05D4              defb " and press ENTER or Control-C to skip): $", 0Dh, 0Ah
05FF              defb "Destination on *:, then press ENTER: $", 0Dh, 0Ah, 0Ah
0628              defb "Be sure the CP/M system disk in drive A:", 0Dh, 0Ah
0652              defb " and press ENTER to reboot...$", 0Dh, 0Ah, "$"
0673              defm "B"
0674              defb 00h, 00h, 00h, 00h
0678              defm "T0T1    SYS"
0683              defs 30  ; 30 bytes of zero padding
06A1              defb "R: $", 0Dh, 0Ah, 0Ah
06A8              defb "Be sure the CP/M system disk in drive A:", 0Dh, 0Ah
06D2              defb " and press ENTER to reboot...$", 0Dh, 0Ah, "$"
06F3              defm "B"
06F4              defb 00h, 00h, 00h, 00h
06F8              defm "T0T1    "


; Data accessed by:
; 01BCh(in SUB03)


; Data accessed by:
; 0233h(in SUB03)


; Data accessed by:
; 0182h(in SUB03), 018Ah(in SUB03), 01B6h(in SUB03), 022Dh(in SUB03)




; Data accessed by:
; 0166h(in SUB03)
; ...
; ...
; ...