Created
July 29, 2024 09:09
-
-
Save hollance/8202149544dba39e4d6c66c94d246bf2 to your computer and use it in GitHub Desktop.
Really old Amiga assembly version of The Game of Nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; The Game of Nim | |
; 68000 assembly source by Matthijs 'Tice' Hollemans of the Fantasy Freaks | |
; converted from an Int*l 8085 (!) coding example... (but improved upon considerably!) | |
; To do: | |
; * intuition stuff (met gadgets enzo) | |
; * Meer pc-relative spul (=kortere executable) | |
************************************************************************** INITIALISATION * | |
opt c- ; case sensitivity uit | |
nolist | |
incdir "include:" | |
include "exec/exec_lib.i" ; exec.library includes | |
include "libraries/dos.i" ; dos.library includes | |
include "libraries/dos_lib.i" | |
list | |
quitchar equ 'q' ; teken om mee te quitten | |
lf equ 10 ; linefeed | |
bufsize equ 80 ; grootte van tijdelijke buffer | |
WRITE MACRO ; "nettere" aanroep van de | |
move.l \1,d2 ; writemsg subroutine | |
move \2,d3 ; \1 is adres van de text, | |
bsr writemsg ; \2 is lengte van de text | |
ENDM | |
**************************************************************************** MAIN PROGRAM * | |
openlib | |
lea dosname(pc),a1 ; open dos.library | |
moveq #0,d0 | |
CALLEXEC OpenLibrary | |
move.l d0,_dosbase ; _dosbase wijst naar dos.library | |
beq quit ; foutje? dan stoppen | |
opencon | |
move.l #conname,d1 ; open een console window | |
move.l #MODE_OLDFILE,d2 | |
CALLDOS Open | |
move.l d0,conhandle ; conhandle wijst naar console | |
beq noconsole ; foutje? dan stoppen | |
start ; hier begint het eigenlijke programma | |
moveq #0,d3 ; d3 leeg maken (voor writemsg) | |
WRITE #nimtext,#nimtextend-nimtext ; intro text | |
moveq #15,d0 ; numsticks op 15 | |
move.b d0,numsticks | |
turn | |
WRITE #update1,#update1end-update1 ; "There are now " | |
lea buffer(pc),a0 ; hier komt ascii waarde van numsticks | |
move.b numsticks,d0 ; numsticks van decimaal naar | |
bsr dec2asc ; ascii converteren | |
WRITE #buffer,#bufsize ; schrijf numsticks (ascii) | |
WRITE #update2,#update2end-update2 ; "sticks remaining." | |
.again | |
WRITE #userchoice,#userchoiceend-userchoice ; vraag om keuze van speler | |
bsr clearbuf ; buffer leeg | |
move.l conhandle,d1 ; lees invoer van gebruiker | |
move.l #buffer,d2 ; en sla die op in buffer | |
moveq #bufsize,d3 ; lees maar 1 teken | |
CALLDOS Read | |
move.b buffer,d0 ; test invoer voor 1, 2 of 3 | |
cmp.b #quitchar,d0 ; quit ? | |
beq finished ; yep -> pleite | |
subi.b #49,d0 ; eerst 49 eraf halen | |
bmi.s .again ; minder dan 0? dan foute invoer | |
cmp.b #3,d0 | |
bpl.s .again ; meer dan 3? dan foute invoer | |
addq #1,d0 ; aantal stokjes dat speler pakte+1 ! | |
sub.b d0,numsticks ; update aantal sticks | |
tst.b numsticks ; hoeveel stokjes zijn er nog? | |
beq userwins ; 0? dan compu verliest | |
computurn | |
lea table(pc),a0 ; computer neemt afh. van het aantal | |
move.b numsticks,d1 ; sticks een waarde uit table | |
move.b (a0,d1),d0 | |
sub.b d0,numsticks ; update aantal sticks | |
addi #48,d0 ; reken d0 om naar ascii | |
move.b d0,buffer ; en zet die in buffer | |
move.b lf,buffer+1 ; met extra linefeed | |
WRITE #compuchoice,#compuchoiceend-compuchoice ; "My choice is: " | |
WRITE #buffer,#2 ; aantal sticks compu pakt | |
tst.b numsticks ; is numsticks 0 ? | |
bne turn ; nee -> volgende beurt | |
WRITE #compuwins,#compuwinsend-compuwins ; compu wint | |
bra start ; begin overnieuw | |
finished ; klaar, alles afsluiten | |
move.l conhandle,d1 ; sluit console window | |
CALLDOS Close | |
noconsole | |
movea.l _dosbase,a1 ; sluit dos.library | |
CALLEXEC CloseLibrary | |
quit | |
rts ; einde programma | |
***************************************************************************** SUBROUTINES * | |
writemsg | |
move.l conhandle,d1 ; schrijf text in d2 (lengte in d3) naar | |
CALLDOS Write ; console window | |
rts | |
dec2asc ; converteert waarde in d0 van decimaal | |
divu #10,d0 ; naar ascii en zet die in (a0) | |
bsr evaldigit ; het decimale getal moet wel 0<x<99 !!! | |
evaldigit | |
addi #48,d0 | |
move.b d0,(a0)+ | |
clr d0 | |
swap d0 | |
rts | |
clearbuf ; maakt de tijdelijke buffer leeg | |
lea buffer(pc),a0 | |
moveq #bufsize-1,d0 | |
.again | |
move.b #0,(a0)+ | |
dbf d0,.again | |
rts | |
userwins | |
WRITE #compulose,#compuloseend-compulose ; speler wint | |
bra start ; start overnieuw | |
************************************************************************************ DATA * | |
even | |
_dosbase | |
dc.l 0 | |
conhandle | |
dc.l 0 | |
dosname | |
DOSNAME | |
conname | |
dc.b "CON:0/100/640/100/The Game of Nim V0.1",0 | |
numsticks | |
dc.b 0 | |
nimtext | |
dc.b lf,"Welcome to Nim - a game of skill!",lf,lf | |
dc.b "I have 15 sticks. You may pick 1, 2 or 3 sticks. Then I will pick.",lf | |
dc.b "You win if you pick up the last 1, 2 or 3 sticks. Type 'q' to quit.",lf,0 | |
nimtextend | |
userchoice | |
dc.b "Your choice: ",0 | |
userchoiceend | |
compulose | |
dc.b lf,"You win!!!",lf,0 | |
compuloseend | |
compuwins | |
dc.b lf,"I win!!!",lf,0 | |
compuwinsend | |
update1 | |
dc.b lf,"There are now ",0 | |
update1end | |
update2 | |
dc.b " sticks remaining.",lf,0 | |
update2end | |
compuchoice | |
dc.b "My choice is: ",0 | |
compuchoiceend | |
table | |
dc.b 0,1,2,3,1,1,2,3,1,1,1,1,1,1,2 | |
buffer | |
dcb.b bufsize,0 | |
version | |
dc.b "$VER: The Game of Nim 1.0 Fantasy Freaks (16.05.95)",0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment