-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.s
61 lines (57 loc) · 1.42 KB
/
main.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
.intel_syntax
.globl main
.set SIZE, 8
.set BUFS, 0x400
.text
main:
cmp %rdi, 2
jne invalid
## Open rom file
mov %rax, 2
mov %rdi, [%rsi+SIZE]
xor %rsi, %rsi # RD_ONLY = 0
xor %rdx, %rdx # Flags are ignored
syscall
cmp %rax, 0
jle readerr
## Read the rom file
## We assume a rom is not larger than 0x400 (1024) bytes
mov %rdi, %rax # File descriptor
lea %rsi, rdbuff
mov %rdx, BUFS
xor %rax, %rax
syscall
cmp %rax, 0
jl readerr
## Put the content in machine RAM at address 0x200
lea %rdi, [ram+0x200]
lea %rsi, rdbuff
mov %rdx, %rax
xor %rax, %rax
call memcpy
## ROM loaded, we can set up the window
lea %rdi, loaded
xor %rax, %rax
call printf
call window_loop
ret
## Error launching the emulator, invalid arguments on startup
invalid:
mov %rax, 1
mov %rdi, 1
lea %rsi, err
mov %rdx, 19
syscall
ret
## Error reading the rom file
readerr:
xor %rax, %rax
lea %rdi, read
call printf
ret
.data
err: .asciz "usage: ./chip8 rom\n"
read: .asciz "Cannot read file\n"
loaded: .asciz "ROM loaded !\n"
.bss
rdbuff: .space BUFS