forked from gardners/c65gs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kickstart_task.a65
122 lines (107 loc) · 2.7 KB
/
kickstart_task.a65
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
; Return the next free task ID
; XXX - Task ID $FF is hypervisor/operating system
; XXX - For now just lie, and always say task $00 is next.
; We should have a process allocation table that we consult.
; (actual suspended processes should be held on SD card in files)
task_get_next_taskid:
lda #$00
rts
task_set_c64_memorymap:
; set contents of CPU registers for exit from hypervisor mode
lda #$00
sta hypervisor_a
sta hypervisor_x
sta hypervisor_y
sta hypervisor_z
sta hypervisor_b
lda #$ff
sta hypervisor_spl
lda #$01
sta hypervisor_sph
lda #$F7 ; All flags except decimal mode
sta hypervisor_flags
lda #$00
sta hypervisor_maplolo
sta hypervisor_maplohi
sta hypervisor_maphilo
sta hypervisor_maphihi
sta hypervisor_maplomb
sta hypervisor_maphimb
lda #$3f
sta hypervisor_cpuport00
sta hypervisor_cpuport01
lda #$00
sta hypervisor_iomode ; C64 IO map
; XXX - disable C65 ROM maps
rts
task_set_pc_to_reset_vector:
; Set PC from $FFFC in ROM, i.e., $802FFFC
ldx #<reset_vector
ldy #>reset_vector
ldz #$02
lda #$00
jsr longpeek
lda kickstart_scratchbyte0
sta hypervisor_pcl
ldx #<reset_vector
inx
ldy #>reset_vector
ldz #$02
lda #$00
jsr longpeek
lda kickstart_scratchbyte0
sta hypervisor_pch
rts
; Set all page entries and current page number to all zeroes
; so that we don't think any page is loaded.
; XXX - Is all zeroes the best value here? Physical page 0 is $00000000, which
; is in chipram. It might be legitimate to try to map that. Perhaps we should set
; the pages to $FFFF instead (but that would reduce available VM space by 16KB).
; Physical page 0 is probably reasonable for now. We can revisit as required.
task_clear_pagetable:
lda #$00
ldx #<hypervisor_vm_currentpage_lo
tcp1: sta $d600,x
inx
cpx #[<hypervisor_vm_pagetable3_physicalpage_hi+1]
bne tcp1
rts
task_erase_processcontrolblock:
; Erase process control block
ldx #$00
txa
tabs1: sta currenttask_block,x
inx
bne tabs1
jsr task_clear_pagetable
; Mark all files as closed
jmp dos_clear_filedescriptors
task_new_processcontrolblock:
jsr task_erase_processcontrolblock
jsr task_get_next_taskid
sta currenttask_id
rts
; Initialise memory to indicate a new blank task.
; (actually, it will be a task preconfigured for C64/C65 mode)
task_asblankslate:
jsr task_new_processcontrolblock
jsr task_set_c64_memorymap
rts
double_restore_trap:
; For now we just want to toggle the CPU speed between 48MHz and
; 1MHz
; enable 48MHz for fast mode instead of 3.5MHz
lda $D054
eor #$40
sta $D054
; enable FAST mode,
lda $D031
ora #$40
sta $D031
; bump border colour so that we know something has happened
lda $D020
inc
and #$0f
sta $D020
; return from hypervisor
sta hypervisor_enterexit_trigger