aboutsummaryrefslogtreecommitdiff
path: root/jindroush/bas2boot/bas2boot.asm
blob: af7752a2e790a97be7185d90dfae1bc1dea9411c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
;Boot stub for loading BASIC programs from short ATR files.
;(c) 1998-1999 Jindrich Kubec <kubecj@asw.cz>

; 20070524 bkw: modified to assemble with dasm
 processor 6502

SIOV		= $E459

DOSVEC		= $0A
RAMTOP		= $6A
LOMEM		= $80
BOOT		= $09
BASICF		= $03F8
PORTB		= $D301

EOPEN		= $EF94

BAS_CONT	= $A97A
BAS_EXEC	= $B755

LOADER_START	= $0700
LOADER_END	= $0800

BASMEMSTART	= $0700

BASPTRSLEN	= $0E
BASPTRSSTART	= LOADER_END - BASPTRSLEN

		org LOADER_START
		
BOOTST:	        .byte 0
		.byte (ENDBOOT-BOOTST+127)/128
		.WORD *-2
		.WORD MAIN_BEG

		CLC
RTS_INSTR:	RTS

		;used for extractor
ORI_LEN:	.WORD 0

MAIN_BEG:
		LDX	#<header
		LDY	#>header
		JSR	$C642

		LDX	#<padding
		LDY	#>padding
		JSR	$C642

		;copy pointers to correct area, add $700
		LDX	#BASPTRSLEN - 1
SETVECT:	CLC
		LDA	BASPTRSSTART,X
		ADC	#>BASMEMSTART
		STA	LOMEM,X
		DEX
		LDA	BASPTRSSTART,X
		STA	LOMEM,X
		DEX
		BPL	SETVECT

		LDA	#$31	;D
		STA	$300
		LDA	#$01	;1
		STA	$301
		LDA	#$52	;read
		STA	$302
		LDA	#$80	;$80 bytes
		STA	$308
		LDA	#$00
		STA	$309
		STA	$30B

		LDA	$82	;buffer address
		STA	$304
		LDA	$83
		STA	$305

		;starting sector
		LDA	# ( (ENDBOOT-BOOTST+127)/128 ) +1
		STA	$30A
SIO_CONT:
		LDA	#$40	;read
		STA	$303

		JSR	SIOV
		LDA	$303
		CMP	#$01
		BEQ	NOERR
		JSR	$C63E
AGAIN:		JMP	AGAIN	;dynamic halt

		;move buffer pointer
NOERR:		

		;LDA	$304
		;CLC
		;ADC	$308
		;STA	$304
		;LDA	$305
		;ADC	$309
		;STA	$305

		;this does the same as the above, but is shorter
		CLC
		LDX	#$FE
LP0:		LDA	$304 - $FE,X
		ADC	$308 - $FE,X
		STA	$304 - $FE,X
		INX
		BNE	LP0

		;increment sector number
		INC	$30A
		BNE	NX1
		INC	$30B
NX1:
		;decrement number of sectors to load
		LDA	SECTORS
		BNE	NX2
		DEC	SECTORS+1
		BMI	BAS_RUN
NX2:		DEC	SECTORS
		JMP	SIO_CONT

BAS_RUN:	LDX	#$FF
		TXS

		LDA	#$0A
		STA	$C9
		LDA	#$00
		STA	BOOT
		STA	BASICF

		;turn on basic
		LDA	#$FD
		STA	PORTB

		;set stack
		LDA	#>BAS_CONT
		PHA
		LDA	#<BAS_CONT - 1
		PHA

	    	LDA	#>BAS_EXEC
		PHA
		LDA	#<BAS_EXEC - 1
		PHA

		LDA	RAMTOP
		BPL	STORE_MEMT
		LDA	#$A0
STORE_MEMT:	STA	RAMTOP

		JMP	EOPEN

header:		.byte "BAS2BOOT (c)1999 Jindroush"
		.byte $1D
		.byte $9B
padding:	.ds BASPTRSSTART - padding - 2 - 1, " "
		.byte $9B
SECTORS:	.WORD 0
BASPTRSSTART2:	.ds BASPTRSLEN

ENDBOOT:

		.END