-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchip8.asm
117 lines (88 loc) · 2.82 KB
/
chip8.asm
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
; Author: rgimad (2021)
; License: GNU GPL v2
format binary as ""
use32
org 0
db 'MENUET01' ; signature
dd 1 ; header version
dd start ; entry point
dd _i_end ; end of image
dd _mem ; required memory size
dd _stacktop ; address of stack top
dd cmdline ; buffer for command line arguments
dd 0 ; buffer for path
include 'constants.inc'
; application's entry point
align 4
start:
mcall 68, 11
mcall 68, 12, IMGBUF_SIZE
mov dword [imgbuf_ptr], eax
stdcall chip8_init ; initialize
DEBUGF DBG_INFO, "app started, args = %s\n", cmdline
DEBUGF DBG_INFO, "MAX_GAME_SIZE = %x = %u\n", MAX_GAME_SIZE, MAX_GAME_SIZE
; xor ecx, ecx
; @@:
; mov al, byte [chip8_fontset + ecx]
; DEBUGF DBG_INFO, "%x ", al
; cmp ecx, 79
; je @f
; inc ecx
; jmp @b
; @@:
mov dword [fread_struct.filename], cmdline
stdcall chip8_loadgame, fread_struct
jz .file_not_found
DEBUGF DBG_INFO, "file was read. bytes: %x %x %x..\n", [memory + 0x200], [memory + 0x200 + 4], [memory + 0x200 + 8]
; mov byte [gfx + 5], 1
; mov byte [gfx + 64], 1
; mov byte [gfx + 65], 1
; mov byte [gfx + 64*2 + 3], 1
.event_loop:
mcall 23, CLOCK_RATE ; wait for event with CLOCK_RATE timeout
;DEBUGF DBG_INFO, "evenp loop iter i\n"
cmp eax, 1
je .event_redraw
cmp eax, 2
je .event_key
cmp eax, 3
je .event_button
jmp .event_default
.event_redraw:
stdcall draw_main_window
jmp .event_default
.event_key:
mcall 2
stdcall keyboard_update, eax
DEBUGF DBG_INFO, "key scancode %x\n", eax:4
jmp .event_default
.event_button:
mcall 17
cmp ah, 1
jne .event_default
mcall -1
.event_default:
stdcall chip8_emulatecycle
cmp byte [chip8_draw_flag], 0
jz @f
; mov byte [gfx + 64*2 + 3], 1 ; DBG
stdcall draw_screen
mov byte [chip8_draw_flag], 0
@@:
stdcall chip8_tick
jmp .event_loop
.file_not_found:
DEBUGF DBG_ERR, "Unable to open game file! eax = %u\n", eax
jmp .exit
.exit:
mov eax, -1
int 0x40
;;;;;;;;;;;;;;;;;;;;;;;
include 'gui.inc'
include 'emu.inc'
include 'utils.inc'
include 'data.inc'
rb 4096 ; reserve for main thread stack
align 16
_stacktop:
_mem: