-
Notifications
You must be signed in to change notification settings - Fork 4
/
autostart64.128.s
102 lines (86 loc) · 2.51 KB
/
autostart64.128.s
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
; C128 boot sector that copies C64 autostart code to $8000, and then switches
; to C64 mode.
.include "config.inc"
.include "defs128.inc"
.include "macros.inc"
.include "boot.inc"
.import __CARTHDR_LOAD__, __CARTHDR_RUN__, __CARTHDR_SIZE__
.import __AUTOSTART64_SIZE__, __AUTOSTART64_LOAD__, __AUTOSTART64_RUN__
.import __VICGO64_SIZE__, __VICGO64_LOAD__, __VICGO64_RUN__
.import __TBUFFR_RUN__
.import devnum_sav
.export AS64
bootctl = $B11 ; boot parameters
C64DEST = $801 ; relocation destination address (c64 basic)
DE = $C3
.segment "GO64"
AS64: ; check if running a c64 program via BRK
lda $03
cmp #$08 ; compare if in $08xx area, then c64 program
beq GO64GO
jmp $B003 ; MONITOR break entry point
GO64GO:
; Screen memory at $400 survives transition to c64 mode.
; Below $400 is wiped on reset. Above $800 (up to $D000) is the loaded program.
; copy go64 routine to boot block screen memory, so that boot block buffer can be freed
LDX #< (__VICGO64_SIZE__ + __CARTHDR_SIZE__ + __AUTOSTART64_SIZE__ + 1)
@loop4: LDA __VICGO64_LOAD__ - 1, X
STA VICGO64 - 1, X
DEX
BNE @loop4
; adjust EAL (end-of load pointer) for 64 mode
sec
lda EAL
sbc SAL
sta EAL
lda EAL+1
sbc SAL+1
sta EAL+1
clc
; lda EAL
; adc #< C64DEST
; sta EAL
inc EAL
lda EAL+1
adc #> C64DEST
sta EAL+1
; tax
; continue execution in screen ram
jmp VICGO64 ; VICGO64 + 3
.segment "VICGO64"
go64:
; reloacte aprogram loaded in c128 mode at $1c00/$8000 to $0801 for c64
relocate:
lda #< C64DEST
sta DE
lda #> C64DEST
sta DE+1
sta $ff01 ; select bank 0
; LDX #220 ; number of pages
ldx EAL+1
inx
sei
LDY #0
@loop3: lda (SAL),Y
sta (DE),Y
INY
bne @loop3
inc SAL+1
inc DE+1
dex
bne @loop3
; copy C64 autostart code into place from screen to $8000,
; swap bytes with original at $8000
; they will be restored when in c64 mode
copy: LDX #< (__CARTHDR_SIZE__ + 1)
@loop:
LDA VICCRTB - 1, X
TAY
LDA __CARTHDR_RUN__ - 1, X
STA VICCRTB - 1, X
TYA
STA __CARTHDR_RUN__ - 1, X
DEX
BNE @loop
stx $ff00
JMP JC64_MODE ; c64 mode will take it from here