-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dasm
134 lines (103 loc) · 2.46 KB
/
main.dasm
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
#define MAX_DRIVE_COUNT 6
:start
;First, we copy the loader at 0xE000.
set A, loader
set B, loader_end
set C, 0xE000
jsr memcpy
jsr detectPeriphs ;Detecting peripherals
set A, 0
set B, 0x8000
hwi [monitor] ;Mapping monitor
set [selected], 0
set B, prompt
set I, 0x8000
jsr write
ife [n_drives], 0
set PC, mainLoop
set I, 0
:readDiskHeaders
;Reading first sector at 0x9000
set A, 2
set X, 0
set Y, 0x9000
hwi [drives + I]
ifn B, 1
ifn B, 2
set PC, readDiskHeaders_skip
jsr loadFloppy_waitFinish
;Checking if disk is BBOS-compatible
set B, str_bootableFloppy
ifn [Y + 0x1FF], 0x55AA
set B, str_noBootableFloppy
set [ptr_names + I], B
ifn [Y + 0x1FF], 0x55AA
set PC, readDiskHeaders_skip
set [drives_compatible + I], 1
set [drives_startSectors + I], [Y + 0x1FD]
set [drives_nSectors + I], [Y + 0x1FE]
:readDiskHeaders_skip
add I, 1
ifn I, [n_drives]
set PC, readDiskHeaders
:mainLoop
;Printing programs with one highlighted
set C, ptr_names
set I, 0x8020
set J, 0
:writeNames
set B, [C]
ife J, [selected] ;if selected, printing highlight
set Z, 0xABAB
jsr write
set Z, 0
add I, 0x20
add C, 1
add J, 1
ifn J, MAX_DRIVE_COUNT
set PC, writeNames
set A, 0
hwi [keyboard] ;Clears keyboard buffer
;Waiting for user to type a letter
set A, 1
:waitKey_loop
hwi [keyboard]
ife C, 0
set PC, waitKey_loop
jsr handleKey
set [0xFF88], [selected]
ife Z, 1
set PC, loadFloppy
set PC, mainLoop
:handleKey
set Z, 0
ifn C, 0x72 ;KEY_R
ifn C, 0x66 ;KEY_F
ifn C, 0x11 ;KEY_RETURN
set PC, POP
ife C, 0x72 ;KEY_R
set PC, handleKey_up
ife C, 0x11 ;RETURN
set PC, handleKey_return
;If not R or return, must be F, don't need to test.
:handleKey_down
add [selected], 1
ife [selected], MAX_DRIVE_COUNT
set [selected], 0
set PC, POP
:handleKey_up
sub [selected], 1
ife [selected], -1
set [selected], MAX_DRIVE_COUNT
ife [selected], MAX_DRIVE_COUNT
sub [selected], 1
set PC, POP ;Back to main loop
:handleKey_return
set Z, 1 ;We want to launch then ^^
set PC, POP
:prompt DAT "Press R/F to select OS"
:selected DAT 0
:bootableFloppy DAT 0
:str_bootableFloppy DAT "BBOS-Compatible disk", 0
:str_noBootableFloppy DAT "No bootable floppy detected", 0
:ptr_names DAT str_noBootableFloppy, str_noBootableFloppy, str_noBootableFloppy, str_noBootableFloppy, str_noBootableFloppy, str_noBootableFloppy ;Comment after name_2 if you only want 2 OS, or name_3 if you want 3.