Skip to content

Commit 5fe6cea

Browse files
committed
Support 80186
1 parent b8ceb6c commit 5fe6cea

2 files changed

Lines changed: 44 additions & 27 deletions

File tree

loader.nasm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
org 7C00h
22
bits 16
3-
cpu 386
3+
cpu 186
44

55
jmp short Start
66

main.nasm

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
org 1000h
22
bits 16
3-
cpu 486
3+
cpu 186
44

55
jmp short Start
66

@@ -13,7 +13,7 @@ endstruc
1313
%define COLUMN_WIDTH 4
1414
%define COLUMN_INTERVAL 25
1515
%define MAX_VISIBLE_COLUMNS 10 ;(80 - 1 + COLUMN_WIDTH) / COLUMN_INTERVAL
16-
%define FIRST_COLUMN_POS_X 70
16+
%define FIRST_COLUMN_POS_X 60
1717
%define GROUND_HEIGHT 4
1818
%define COLUMN_TOP_MIN_Y 2
1919
%define COLUMN_TOP_MAX_Y 16 - GROUND_HEIGHT
@@ -62,13 +62,15 @@ StartMenu:
6262
int 16h
6363
jmp StartGame
6464
StartGame:
65-
mov eax, [playerStartY] ; set player pos and speed
66-
mov [playerY], eax
67-
mov eax, [playerStartYVel]
68-
mov [playerYVel], eax
65+
mov si, playerStartY ; set player pos and speed
66+
mov di, playerY
67+
call Copy32
68+
mov si, playerStartYVel
69+
mov di, playerYVel
70+
call Copy32
6971
mov word [score], 0
7072
mov byte [collCnt], 0
71-
mov bl, FIRST_COLUMN_POS_X
73+
mov dl, FIRST_COLUMN_POS_X
7274
call SpawnColumn
7375
7476
mov cx, 80 ; draw ground
@@ -90,9 +92,10 @@ StartGame:
9092
jz .noJump
9193
xor ah, ah
9294
int 16h ;TODO: check if this is the jump key
93-
mov eax, [jumpSpeed]
94-
mov [playerYVel], eax
95-
.noJump:
95+
mov si, jumpSpeed
96+
mov di, playerYVel
97+
call Copy32
98+
.noJump:
9699
fld dword [playerYVel] ; update velocity and y position
97100
fadd dword [gravityAcc]
98101
fld dword [playerVelFactor]
@@ -107,7 +110,8 @@ StartGame:
107110
108111
cmp byte [playerYInt], 1 ; check if player is too high
109112
jns .yPositive
110-
mov dword [playerY], 0
113+
mov word [playerY], 0
114+
mov word [playerY + 2], 0
111115
mov byte [playerYInt], 0
112116
.yPositive:
113117
@@ -126,7 +130,8 @@ StartGame:
126130
push dx
127131
xor dh, dh
128132
.printRowLoop:
129-
movzx cx, [columnWidth]
133+
xor cx, cx
134+
mov cl, [columnWidth]
130135
mov dl, [si+column.posX]
131136
test dl, dl
132137
jns .xNotNeg
@@ -165,13 +170,14 @@ StartGame:
165170
mov ah, [collCnt]
166171
dec ah
167172
mul ah
168-
movzx di, al
169-
add di, colls
173+
xor bx, bx
174+
mov bl, al
175+
add bx, colls
170176
mov al, 80
171-
sub al, [di+column.posX]
177+
sub al, [bx+column.posX]
172178
cmp al, COLUMN_INTERVAL
173179
jne .noSpawn
174-
mov bl, 79 ; (79 - COLUMN_WIDTH)
180+
mov dl, 79 ; (79 - COLUMN_WIDTH)
175181
call SpawnColumn
176182
.noSpawn:
177183
@@ -236,7 +242,8 @@ StartGame:
236242
mov al, [collCnt]
237243
mov ah, column_size
238244
mul ah
239-
movzx cx, al
245+
xor cx, cx
246+
mov cl, al
240247
rep movsb
241248
.noRemove:
242249
@@ -285,6 +292,15 @@ jmp DeadLoop
285292
;================================== Subroutines ==================================
286293
;=================================================================================
287294

295+
; args: si, di
296+
; invalidates: ax
297+
Copy32:
298+
mov ax, [si]
299+
mov [di], ax
300+
mov ax, [si + 2]
301+
mov [di + 2], ax
302+
ret
303+
288304
; args: bh = color
289305
ClearScreen:
290306
mov ah, 06h
@@ -295,23 +311,24 @@ ClearScreen:
295311
int 10h
296312
ret
297313

298-
; args: bl = x
314+
; args: dl = x
299315
; invalidates: ax, bx, dx, di
300316
SpawnColumn:
301317
mov al, column_size
302318
mov ah, [collCnt]
303319
mul ah
304-
movzx di, al
305-
add di, colls
306-
mov [di+column.posX], bl
320+
xor bx, bx
321+
mov bl, al
322+
add bx, colls
323+
mov [bx+column.posX], dl
307324
call NextRandomNum
308325
xor dx, dx
309-
mov bx, COLUMN_TOP_MAX_Y - COLUMN_TOP_MIN_Y
310-
div bx
326+
mov di, COLUMN_TOP_MAX_Y - COLUMN_TOP_MIN_Y
327+
div di
311328
add dx, COLUMN_TOP_MIN_Y
312-
mov byte [di+column.highY], dl
329+
mov byte [bx+column.highY], dl
313330
add dl, [columnSpaceHeight]
314-
mov byte [di+column.lowY], dl
331+
mov byte [bx+column.lowY], dl
315332
inc byte [collCnt]
316333
ret
317334

@@ -375,7 +392,7 @@ columnSpaceHeight db 8
375392
groundHeight db GROUND_HEIGHT
376393

377394
; VirtualBox sometimes appears to have messed up clock. If so, multiply values below by 4.
378-
updateInterval dd 1_000_000 / 20
395+
updateInterval dd 1_000_000 / 20 * 4
379396
restartDelay dd 250_000
380397

381398
%include "commonSubroutines.nasm"

0 commit comments

Comments
 (0)