スキップしてメイン コンテンツに移動

PDP11: Sengoku Battle Game


I wrote sengoku battle game in PDP11 (assembler language) a few years back.
Not sure how many people are interested in the source code but I put it below.
;;;game program for PDP-11, battle in the Sengoku period
;;;programed by Duke Software, 2003

 CHIN  = 172020
 SETCOLOR = 172060
 DRAWLINE = 172074
 FILLRECT = 172104
 FILLARCT = 172114
 CLRSCREEN = 172130
 VRAM   = 160000
 ENDVRAM  = 167636
 
 FIRSTMESVRAM = 163430
 INFNAMEVRAM = 165000
 CHADATVRAM = 165240
 OTHERCHADATVRAM = 165400
 SHIFTNAMEVRAM = 2
 SHIFTABVRAM = 46
 SHIFTSOLVRAM = 56
 SHIFTMORVRAM = 64
 SHIFTTYPVRAM = 72
 MESVRAM  = 167500
 TURNVRAM = 167524
 WINMESVRAM = 167526
 TURNNUMBERVRAM = 165110
 VRAMLOOP = 240   ;one loop of the VRAM number
 INFAREAYVRAM = 256.
 INFTEAM0XVRAM = 0.
 INFTEAM1XVRAM = 480.

 TEAM0FACEXADRESS= 320.
 TEAM1FACEXADRESS= 415.
 FACEYADRESS = 256.
 MAXCHARANUMBER = 30.
 MAXTEAM0NUMBER = 14.
 MAXMORALE = 120.
 MAPSIZE  = 1280.
 TWICEMAPSIZE = 2560.

 MAXXPOS  = 79.
 MAXYPOS  = 15.
 MINXPOS  = 0.
 MINYPOS  = 0.
 MINXPOSADD1 = 1.
 MINYPOSADD1 = 1.
 MAXXPOSSUB1 = 78.
 MAXYPOSSUB1 = 14.
 
 KIBA  = 2.   ;character type
 YARI  = 1.
 TEPPOU  = 3.

 LIVE  = 1.   ;character live or dead
 DEAD  = 0.

 PLAYER  = 0.
 COMPUTER = 1.

 NOCHECKMPOS = 80.
 MAXDISTANCE = 135.
 CHANOTMOVE = 177777

 FIRSTMPOS = 177777  ;initilize data MPOS
 NOCHARACTER = 177777  ;initilize data CPOS
 NOTATTACKEXECUTE= 177777

 COMMOVEND = 0
 COMRIGHTMOV = 1
 COMLEFTMOV = 2
 COMDOWNMOV = 3
 COMUPMOV = 4

 COMROUTESIZE = 100.

;;;geographical data---------------------------------------------------------------
;;;from left, 
;;;1st digit ---distinction number
;;;2nd digit ---attack effect
;;;3rd digit ---defence effect
;;;4th digit ---comsumption of move ability
 PL = 0334    ;plain
 HI = 1345    ;hill
 LO = 2422    ;load
 RI = 3117    ;river
 WO = 4246    ;wood

;;;color data of face graphic------------------------------------------------------
 WHI  = 0.   ;white
 LGR  = 1.   ;light gray
 DGR  = 2.   ;dark gray
 BLK  = 3.   ;black
 YEL  = 4.   ;yellow
 BRO  = 5.   ;brown
 RED  = 6.   ;red
 LBL  = 7.   ;light blue
 DBL  = 8.   ;dark blue
 LPI  = 9.   ;light pink
 GRE  = 10.   ;green
 RBR  = 11.   ;red brown
 PBR  = 12.   ;purple brown
 DOTEND  = 177777  ;graphic end data

 .= 1000
;;;-----------------------------------------------------------------------------;;;
;;;   DATA       ;;;
;;;-----------------------------------------------------------------------------;;;
;;Uesugi Kenshin face graphic data
UEFACE: .BYTE LBL,LBL,LBL,BLK,DGR,WHI,WHI,WHI,WHI,WHI,WHI,WHI,WHI,WHI,WHI,WHI
 .BYTE WHI,WHI,WHI,WHI,DGR,LGR,DGR,LGR,DGR,DGR,DGR,DGR,DGR,DGR,DGR,DGR
 .BYTE LBL,LBL,BLK,DGR,WHI,DGR,WHI,WHI,DGR,BLK,BLK,WHI,DGR,BLK,BLK,WHI
 .BYTE WHI,WHI,WHI,DGR,LGR,DGR,LGR,DGR,DGR,DGR,DGR,DGR,DGR,DGR,DGR,BLK
 .BYTE LBL,BLK,BLK,WHI,DGR,DGR,WHI,DGR,WHI,DGR,BLK,WHI,DGR,BLK,BLK,WHI
 .BYTE WHI,WHI,DGR,LGR,DGR,LGR,DGR,DGR,DGR,DGR,DGR,DGR,DGR,DGR,BLK,DGR
 .BYTE LBL,BLK,WHI,DGR,WHI,DGR,DGR,WHI,DGR,DGR,BLK,WHI,DGR,BLK,DGR,WHI
 .BYTE WHI,WHI,WHI,DGR,B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,WHI,GRE,GRE,BLK,LBL,DBL,BLK
 .BYTE LBL,BRO,BLK,RBR,BLK,BLK,BLK,BLK,GRE,BLK,DGR,LGR,DGR,BLK,LGR,LGR
 .BYTE WHI,LGR,DGR,WHI,LGR,BLK,DGR,BLK,BLK,WHI,BLK,GRE,GRE,BLK,WHI,DBL
 .BYTE BLK,GRE,BLK,BLK,BLK,LBL,BLK,GRE,BLK,BLK,BLK,GRE,BLK,LGR,BLK,RBR
 .BYTE WHI,LGR,DGR,WHI,LGR,LGR,DGR,WHI,WHI,BLK,DGR,BLK,GRE,GRE,BLK,WHI
 .BYTE DBL,BLK,BRO,RBR,BLK,LBL,BLK,BLK,GRE,BLK,BLK,BLK,BLK,RBR,BLK,RBR
 .BYTE WHI,DGR,WHI,WHI,LGR,LGR,DGR,DGR,BLK,WHI,BLK,GRE,BLK,GRE,BLK,DGR
 .BYTE WHI,DBL,BLK,BLK,WHI,LBL,BLK,GRE,GRE,BLK,BLK,BLK,RBR,BLK,RBR,BLK
 .BYTE WHI,DGR,DGR,WHI,WHI,BLK,DGR,WHI,WHI,DGR,BLK,BLK,BLK,BLK,BLK,BLK
 .BYTE BLK,BLK,BLK,BLK,BLK,BLK,BLK,BLK,BLK,BLK,BLK,RBR,BLK,RBR,RBR,BLK
 .BYTE DOTEND
 .EVEN


;;;--------infomation name of character paramater----------------------------------
INFNAM: .ASCII /   UESUGI GUNDAN   /
 .ASCII /AT/
 .ASCII /DE/
 .ASCII /SOL/
 .ASCII /MOR/
 .ASCII /TYP/
 .ASCII /         TURN   /
 .ASCII /   TAKEDA GUNDAN   /
 .ASCII /AT/
 .ASCII /DE/
 .ASCII /SOL/
 .ASCII /MOR/
 .ASCIZ /TYP/
 .EVEN

TEAM0NAM: .ASCIZ /UESUGI GUN/
TEAM1NAM: .ASCIZ /TAKEDA GUN/


;;;--------character data----------------------------------------------------------
;;;character's character
;;;example:"A, B, C,....etc."
CHACHAR:.WORD 101, 102, 103, 104, 105, 106, 107, 110
 .WORD 141, 142, 143, 144, 145, 146, 147, 150

;;;character team
CHATEAM:.WORD 0., 0., 0., 0., 0., 0., 0., 0.
 .WORD 1., 1., 1., 1., 1., 1., 1., 1.

;;;character live or dead flag
CHALIFE:.WORD LIVE, LIVE, LIVE, LIVE, LIVE, LIVE, LIVE, LIVE
 .WORD LIVE, LIVE, LIVE, LIVE, LIVE, LIVE, LIVE, LIVE

;;;character name
CHANAME:.ASCIZ /Uesugi   Kenshin  /
 .EVEN
 .ASCIZ /Kakizaki Kageie   /
 .EVEN
 .ASCIZ /Amakasu  Kagemochi/
 .EVEN
 .ASCIZ /Irobe    Katsunaga/
 .EVEN
 .ASCIZ /Saito    Tomonobu /
 .EVEN
 .ASCIZ /Naoe     Kagetsuna/
 .EVEN
 .ASCIZ /Honjo    Shigenaga/
 .EVEN
 .ASCIZ /Kitajo   Kagehiro /
 .EVEN
 .ASCIZ /Takeda   Shingen  /
 .EVEN
 .ASCIZ /Yamagata Masakage /
 .EVEN
 .ASCIZ /Baba     Nobufusa /
 .EVEN
 .ASCIZ /Kosaka   Masanobu /
 .EVEN
 .ASCIZ /Naito    Masatoyo /
 .EVEN
 .ASCIZ /Takeda   Nobushige/
 .EVEN
 .ASCIZ /Anayama  Nobukimi /
 .EVEN
 .ASCIZ /Obu      Toramasa /
 .EVEN

;;;character attack ability
CHAATAB:.WORD 16., 15., 12., 13., 10., 9., 13., 12.
 .WORD 14., 13., 12., 10., 11., 10., 6., 12.

;;;character defense ability
CHADEAB:.WORD 15., 8., 9., 7., 11., 8., 9., 6.
 .WORD 16., 11., 14., 12., 11., 13., 8., 9.

;;;character x position
CHAXPOS:.WORD 20., 20., 20., 20., 20., 20., 20., 20.
 .WORD 40., 40., 40., 40., 40., 40., 40., 40.

;;;character y position
CHAYPOS:.WORD 3., 4., 5., 6., 7., 8., 9., 10.
 .WORD 3., 4., 5., 6., 7., 8., 9., 10.

;;;character morale
CHAMORA:.WORD 100., 100., 100., 100., 100., 100., 100., 100.
 .WORD 100., 100., 100., 100., 100., 100., 100., 100.

;;;character soldier number
CHASOL: .WORD 999., 500., 500., 800., 500., 400., 800., 500.
 .WORD 999., 500., 500., 800., 500., 400., 800., 500.

;;;character move ability
CHAMOAB:.WORD 20., 16., 16., 12., 10., 16., 16., 12.
 .WORD 16., 16., 16., 16., 12., 12., 10., 16.

;;;character unit type
CHATYPE:.WORD KIBA, KIBA, KIBA, YARI, TEPPOU, KIBA, KIBA, YARI
 .WORD KIBA, KIBA, KIBA, KIBA, YARI, YARI, TEPPOU, KIBA

;;;enemy character which can be attacked
CHAATBL:.WORD 0., 0., 0., 0., 0., 0., 0., 0.
 .WORD 0., 0., 0., 0., 0., 0., 0., 0.

;;;control data ( computer or player )
CHAMANI:.WORD COMPUTER, COMPUTER, COMPUTER, COMPUTER, COMPUTER, COMPUTER, COMPUTER, COMPUTER
 .WORD COMPUTER, COMPUTER, COMPUTER, COMPUTER, COMPUTER, COMPUTER, COMPUTER, COMPUTER


;;;----------character initilize data----------------------------------------------
FISOL: .WORD 999., 800., 700., 800., 700., 900., 800., 700.
 .WORD 999., 800., 900., 900., 700., 800., 800., 800.

FIMORA: .WORD 100., 100., 100., 100., 100., 100., 100., 100.
 .WORD 100., 100., 100., 100., 100., 100., 100., 100.

FIXPOS: .WORD 30., 40., 40., 40., 40., 41., 39., 42.
 .WORD 76., 75., 3., 4., 75., 75., 75., 75.

;;;character y position
FIYPOS: .WORD 3., 4., 5., 6., 7., 8., 9., 10.
 .WORD 7., 6., 1., 2., 8., 7., 5., 9.


;;;--------map data----------------------------------------------------------------
GEOMAP: .WORD HI,HI,HI,HI,HI,HI,HI,HI,HI,HI;GEOMAP[0000]--GEOMAP[0009], (00,00)--(09,00)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,LO;GEOMAP[0010]--GEOMAP[0019], (10,00)--(19,00)
 .WORD PL,PL,PL,PL,PL,RI,PL,PL,PL,PL;GEOMAP[0020]--GEOMAP[0029], (20,00)--(29,00)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0030]--GEOMAP[0039], (30,00)--(39,00)
 .WORD PL,PL,WO,WO,WO,WO,WO,PL,PL,PL;GEOMAP[0040]--GEOMAP[0049], (40,00)--(49,00)
 .WORD LO,PL,PL,HI,HI,HI,HI,HI,HI,HI;GEOMAP[0050]--GEOMAP[0059], (50,00)--(59,00)
 .WORD HI,HI,HI,HI,HI,LO,HI,HI,HI,PL;GEOMAP[0060]--GEOMAP[0069], (60,00)--(69,00)
 .WORD PL,PL,RI,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0070]--GEOMAP[0079], (70,00)--(79,00)

 .WORD HI,HI,HI,HI,HI,HI,HI,HI,HI,PL;GEOMAP[0080]--GEOMAP[0089], (00,01)--(09,01)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,LO;GEOMAP[0090]--GEOMAP[0099], (10,01)--(19,01)
 .WORD PL,PL,PL,PL,PL,RI,PL,PL,PL,PL;GEOMAP[0100]--GEOMAP[0109], (20,01)--(29,01)
 .WORD PL,PL,PL,WO,PL,PL,PL,PL,PL,PL;GEOMAP[0110]--GEOMAP[0119], (30,01)--(39,01)
 .WORD PL,PL,PL,WO,PL,PL,PL,PL,PL,PL;GEOMAP[0120]--GEOMAP[0129], (40,01)--(49,01)
 .WORD LO,LO,PL,HI,HI,HI,HI,HI,HI,HI;GEOMAP[0130]--GEOMAP[0139], (50,01)--(59,01)
 .WORD HI,HI,HI,HI,LO,LO,HI,PL,PL,PL;GEOMAP[0140]--GEOMAP[0149], (60,01)--(69,01)
 .WORD PL,RI,RI,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0150]--GEOMAP[0159], (70,01)--(79,01)

 .WORD HI,HI,HI,HI,HI,HI,HI,HI,HI,PL;GEOMAP[0160]--GEOMAP[0169], (00,02)--(09,02)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,LO,LO;GEOMAP[0170]--GEOMAP[0179], (10,02)--(19,02)
 .WORD PL,PL,PL,PL,PL,RI,RI,PL,PL,PL;GEOMAP[0180]--GEOMAP[0189], (20,02)--(29,02)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0190]--GEOMAP[0199], (30,02)--(39,02)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0200]--GEOMAP[0209], (40,02)--(49,02)
 .WORD PL,LO,PL,PL,HI,HI,HI,HI,HI,HI;GEOMAP[0210]--GEOMAP[0219], (50,02)--(59,02)
 .WORD HI,LO,LO,LO,LO,HI,HI,PL,PL,PL;GEOMAP[0220]--GEOMAP[0229], (60,02)--(69,02)
 .WORD PL,RI,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0230]--GEOMAP[0239], (70,02)--(79,02)

 .WORD HI,HI,HI,HI,PL,PL,PL,PL,PL,PL;GEOMAP[0240]--GEOMAP[0249], (00,03)--(09,03)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,LO,PL;GEOMAP[0250]--GEOMAP[0259], (10,03)--(19,03)
 .WORD PL,PL,PL,PL,PL,PL,RI,RI,PL,PL;GEOMAP[0260]--GEOMAP[0269], (20,03)--(29,03)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0270]--GEOMAP[0279], (30,03)--(39,03)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0280]--GEOMAP[0289], (40,03)--(49,03)
 .WORD PL,LO,LO,PL,PL,PL,PL,HI,HI,HI;GEOMAP[0290]--GEOMAP[0299], (50,03)--(59,03)
 .WORD HI,LO,HI,HI,HI,HI,PL,PL,PL,PL;GEOMAP[0300]--GEOMAP[0309], (60,03)--(69,03)
 .WORD RI,RI,PL,PL,HI,HI,HI,HI,HI,HI;GEOMAP[0310]--GEOMAP[0319], (70,03)--(79,03)

 .WORD HI,HI,HI,PL,PL,PL,PL,PL,WO,WO;GEOMAP[0320]--GEOMAP[0329], (00,04)--(09,04)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,LO,PL;GEOMAP[0330]--GEOMAP[0339], (10,04)--(19,04)
 .WORD PL,PL,PL,PL,PL,PL,PL,RI,RI,PL;GEOMAP[0340]--GEOMAP[0349], (20,04)--(29,04)
 .WORD PL,PL,PL,PL,PL,PL,PL,WO,PL,PL;GEOMAP[0350]--GEOMAP[0359], (30,04)--(39,04)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0360]--GEOMAP[0369], (40,04)--(49,04)
 .WORD PL,PL,LO,PL,PL,PL,PL,PL,HI,HI;GEOMAP[0370]--GEOMAP[0379], (50,04)--(59,04)
 .WORD HI,LO,HI,PL,PL,PL,PL,PL,PL,RI;GEOMAP[0380]--GEOMAP[0389], (60,04)--(69,04)
 .WORD RI,PL,PL,PL,HI,HI,HI,HI,HI,HI;GEOMAP[0390]--GEOMAP[0399], (70,04)--(79,04)

 .WORD HI,PL,PL,PL,PL,PL,PL,PL,WO,WO;GEOMAP[0400]--GEOMAP[0409], (00,05)--(09,05)
 .WORD PL,PL,PL,PL,PL,PL,PL,LO,LO,PL;GEOMAP[0410]--GEOMAP[0419], (10,05)--(19,05)
 .WORD PL,PL,PL,HI,PL,PL,PL,PL,RI,RI;GEOMAP[0420]--GEOMAP[0429], (20,05)--(29,05)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0430]--GEOMAP[0439], (30,05)--(39,05)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0440]--GEOMAP[0449], (40,05)--(49,05)
 .WORD PL,PL,LO,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0450]--GEOMAP[0459], (50,05)--(59,05)
 .WORD PL,LO,PL,PL,RI,PL,PL,PL,RI,RI;GEOMAP[0460]--GEOMAP[0469], (60,05)--(69,05)
 .WORD PL,PL,PL,HI,HI,HI,HI,HI,HI,HI;GEOMAP[0470]--GEOMAP[0479], (70,05)--(79,05)

 .WORD PL,PL,PL,PL,PL,PL,PL,PL,WO,WO;GEOMAP[0480]--GEOMAP[0489], (00,06)--(09,06)
 .WORD WO,PL,PL,PL,PL,PL,PL,LO,PL,PL;GEOMAP[0490]--GEOMAP[0499], (10,06)--(19,06)
 .WORD PL,PL,HI,HI,HI,PL,PL,PL,PL,RI;GEOMAP[0500]--GEOMAP[0509], (20,06)--(29,06)
 .WORD RI,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0510]--GEOMAP[0519], (30,06)--(39,06)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0520]--GEOMAP[0529], (40,06)--(49,06)
 .WORD PL,PL,LO,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0530]--GEOMAP[0539], (50,06)--(59,06)
 .WORD LO,LO,PL,RI,RI,RI,PL,RI,RI,PL;GEOMAP[0540]--GEOMAP[0549], (60,06)--(69,06)
 .WORD PL,PL,PL,PL,HI,HI,HI,HI,HI,HI;GEOMAP[0550]--GEOMAP[0559], (70,06)--(79,06)

 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0560]--GEOMAP[0569], (00,07)--(09,07)
 .WORD PL,PL,PL,PL,PL,PL,PL,LO,PL,PL;GEOMAP[0570]--GEOMAP[0579], (10,07)--(19,07)
 .WORD PL,PL,PL,HI,PL,PL,PL,PL,PL,PL;GEOMAP[0580]--GEOMAP[0589], (20,07)--(29,07)
 .WORD RI,RI,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0590]--GEOMAP[0599], (30,07)--(39,07)
 .WORD PL,LO,LO,LO,LO,LO,LO,LO,LO,LO;GEOMAP[0600]--GEOMAP[0609], (40,07)--(49,07)
 .WORD LO,LO,LO,PL,PL,PL,PL,LO,LO,LO;GEOMAP[0610]--GEOMAP[0619], (50,07)--(59,07)
 .WORD LO,PL,RI,RI,PL,RI,RI,RI,PL,PL;GEOMAP[0620]--GEOMAP[0629], (60,07)--(69,07)
 .WORD PL,HI,HI,HI,HI,HI,HI,HI,HI,HI;GEOMAP[0630]--GEOMAP[0639], (70,07)--(79,07)

 .WORD PL,PL,PL,PL,PL,WO,WO,WO,WO,WO;GEOMAP[0640]--GEOMAP[0649], (00,08)--(09,08)
 .WORD WO,PL,PL,PL,PL,PL,LO,LO,LO,PL;GEOMAP[0650]--GEOMAP[0659], (10,08)--(19,08)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0660]--GEOMAP[0669], (20,08)--(29,08)
 .WORD PL,RI,RI,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0670]--GEOMAP[0679], (30,08)--(39,08)
 .WORD PL,LO,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0680]--GEOMAP[0689], (40,08)--(49,08)
 .WORD PL,PL,LO,LO,LO,LO,LO,LO,PL,PL;GEOMAP[0690]--GEOMAP[0699], (50,08)--(59,08)
 .WORD PL,PL,RI,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0700]--GEOMAP[0709], (60,08)--(69,08)
 .WORD HI,HI,HI,HI,HI,HI,HI,HI,HI,HI;GEOMAP[0710]--GEOMAP[0719], (70,08)--(79,08)

 .WORD PL,PL,PL,PL,PL,WO,WO,WO,WO,WO;GEOMAP[0720]--GEOMAP[0729], (00,09)--(09,09)
 .WORD WO,PL,PL,PL,PL,PL,LO,PL,LO,PL;GEOMAP[0730]--GEOMAP[0739], (10,09)--(19,09)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0740]--GEOMAP[0749], (20,09)--(29,09)
 .WORD PL,PL,RI,RI,PL,PL,PL,PL,PL,PL;GEOMAP[0750]--GEOMAP[0759], (30,09)--(39,09)
 .WORD PL,LO,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0760]--GEOMAP[0769], (40,09)--(49,09)
 .WORD PL,PL,LO,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0770]--GEOMAP[0779], (50,09)--(59,09)
 .WORD PL,PL,RI,PL,PL,PL,PL,PL,PL,HI;GEOMAP[0780]--GEOMAP[0789], (60,09)--(69,09)
 .WORD HI,HI,HI,HI,HI,HI,HI,HI,HI,HI;GEOMAP[0790]--GEOMAP[0799], (70,09)--(79,09)

 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0800]--GEOMAP[0809], (00,10)--(09,10)
 .WORD PL,PL,PL,PL,PL,PL,LO,PL,LO,LO;GEOMAP[0810]--GEOMAP[0819], (10,10)--(19,10)
 .WORD LO,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0820]--GEOMAP[0829], (20,10)--(29,10)
 .WORD PL,PL,PL,RI,RI,PL,PL,PL,PL,PL;GEOMAP[0830]--GEOMAP[0839], (30,10)--(39,10)
 .WORD PL,LO,PL,PL,WO,WO,PL,PL,PL,PL;GEOMAP[0840]--GEOMAP[0849], (40,10)--(49,10)
 .WORD PL,PL,LO,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0850]--GEOMAP[0859], (50,10)--(59,10)
 .WORD PL,RI,RI,PL,PL,PL,PL,PL,HI,HI;GEOMAP[0860]--GEOMAP[0869], (60,10)--(69,10)
 .WORD HI,HI,HI,HI,HI,HI,HI,HI,HI,HI;GEOMAP[0870]--GEOMAP[0879], (70,10)--(79,10)

 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0880]--GEOMAP[0889], (00,11)--(09,11)
 .WORD PL,PL,PL,PL,PL,LO,LO,PL,PL,PL;GEOMAP[0890]--GEOMAP[0899], (10,11)--(19,11)
 .WORD LO,LO,LO,LO,LO,LO,LO,LO,LO,LO;GEOMAP[0900]--GEOMAP[0909], (20,11)--(29,11)
 .WORD LO,LO,LO,LO,LO,LO,LO,LO,LO,LO;GEOMAP[0910]--GEOMAP[0919], (30,11)--(39,11)
 .WORD LO,LO,PL,PL,WO,WO,PL,PL,PL,PL;GEOMAP[0920]--GEOMAP[0929], (40,11)--(49,11)
 .WORD PL,PL,LO,LO,PL,PL,PL,PL,PL,PL;GEOMAP[0930]--GEOMAP[0939], (50,11)--(59,11)
 .WORD PL,RI,RI,PL,PL,PL,PL,HI,HI,HI;GEOMAP[0940]--GEOMAP[0949], (60,11)--(69,11)
 .WORD HI,HI,HI,HI,HI,HI,HI,HI,HI,HI;GEOMAP[0950]--GEOMAP[0959], (70,11)--(79,11)

 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0960]--GEOMAP[0969], (00,12)--(09,12)
 .WORD PL,PL,PL,PL,PL,LO,PL,PL,PL,PL;GEOMAP[0970]--GEOMAP[0979], (10,12)--(19,12)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[0980]--GEOMAP[0989], (20,12)--(29,12)
 .WORD PL,PL,PL,PL,PL,RI,PL,PL,PL,PL;GEOMAP[0990]--GEOMAP[0999], (30,12)--(39,12)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[1000]--GEOMAP[1009], (40,12)--(49,12)
 .WORD PL,PL,PL,LO,PL,PL,PL,PL,PL,PL;GEOMAP[1010]--GEOMAP[1019], (50,12)--(59,12)
 .WORD PL,RI,RI,PL,PL,PL,PL,HI,HI,HI;GEOMAP[1020]--GEOMAP[1029], (60,12)--(69,12)
 .WORD HI,HI,HI,HI,HI,HI,HI,HI,HI,HI;GEOMAP[1030]--GEOMAP[1039], (70,12)--(79,12)

 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[1040]--GEOMAP[1049], (00,13)--(09,13)
 .WORD PL,PL,PL,PL,PL,LO,PL,PL,PL,PL;GEOMAP[1050]--GEOMAP[1059], (10,13)--(19,13)
 .WORD PL,PL,WO,WO,PL,PL,PL,PL,PL,PL;GEOMAP[1060]--GEOMAP[1069], (20,13)--(29,13)
 .WORD PL,PL,PL,PL,PL,RI,PL,PL,PL,PL;GEOMAP[1070]--GEOMAP[1079], (30,13)--(39,13)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[1080]--GEOMAP[1089], (40,13)--(49,13)
 .WORD PL,PL,PL,LO,PL,PL,PL,PL,PL,PL;GEOMAP[1090]--GEOMAP[1099], (50,13)--(59,13)
 .WORD PL,RI,RI,PL,PL,PL,PL,HI,HI,HI;GEOMAP[1100]--GEOMAP[1109], (60,13)--(69,13)
 .WORD HI,HI,HI,HI,HI,HI,HI,HI,HI,HI;GEOMAP[1110]--GEOMAP[1119], (70,13)--(79,13)

 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[1120]--GEOMAP[1129], (00,14)--(09,14)
 .WORD PL,PL,PL,PL,LO,LO,PL,PL,PL,PL;GEOMAP[1130]--GEOMAP[1139], (10,14)--(19,14)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[1140]--GEOMAP[1149], (20,14)--(29,14)
 .WORD PL,PL,PL,PL,PL,RI,PL,PL,PL,WO;GEOMAP[1150]--GEOMAP[1159], (30,14)--(39,14)
 .WORD WO,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[1160]--GEOMAP[1169], (40,14)--(49,14)
 .WORD PL,PL,PL,LO,PL,PL,PL,PL,PL,PL;GEOMAP[1170]--GEOMAP[1179], (50,14)--(59,14)
 .WORD PL,RI,RI,PL,PL,PL,PL,HI,HI,HI;GEOMAP[1180]--GEOMAP[1189], (60,14)--(69,14)
 .WORD HI,HI,HI,HI,HI,HI,HI,HI,HI,HI;GEOMAP[1190]--GEOMAP[1199], (70,14)--(79,14)

 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[1200]--GEOMAP[1209], (00,15)--(09,15)
 .WORD PL,PL,PL,PL,LO,PL,PL,PL,PL,PL;GEOMAP[1210]--GEOMAP[1219], (10,15)--(19,15)
 .WORD PL,PL,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[1220]--GEOMAP[1229], (20,15)--(29,15)
 .WORD PL,PL,PL,PL,PL,RI,PL,PL,PL,WO;GEOMAP[1230]--GEOMAP[1239], (30,15)--(39,15)
 .WORD WO,WO,PL,PL,PL,PL,PL,PL,PL,PL;GEOMAP[1240]--GEOMAP[1249], (40,15)--(49,15)
 .WORD PL,PL,PL,LO,PL,PL,PL,PL,PL,PL;GEOMAP[1250]--GEOMAP[1259], (50,15)--(59,15)
 .WORD PL,RI,RI,PL,PL,PL,PL,HI,HI,HI;GEOMAP[1260]--GEOMAP[1269], (60,15)--(69,15)
 .WORD HI,HI,HI,HI,HI,HI,HI,HI,HI,HI;GEOMAP[1270]--GEOMAP[1279], (70,15)--(79,15)

;;;other data----------------------------------------------------------------------
MPOS: .BLKW MAPSIZE   ;movable position information
CPOS: .BLKW MAPSIZE   ;the information of character current position
MOABPOS:.BLKW MAPSIZE   ;the rest of character's move ability
CROUTE: .BLKW COMROUTESIZE  ;computer serch route memory

;;;character type information
CHAKIBA:.ASCIZ / K/
 .EVEN
CHAYARI:.ASCIZ / Y/
 .EVEN
CHATEPO:.ASCIZ / T/
 .EVEN

;;;messages
METURN: .ASCIZ /    TURN/
 .EVEN
MEWIN: .ASCIZ /WIN!/
 .EVEN
MESPACE:.ASCIZ /                 /
 .EVEN
MECHOI: .ASCIZ /  UESUGI   vs  TAKEDA  /
 .EVEN
MEPLPL: .ASCIZ /1.player   vs  player  /
 .EVEN
MECOPL: .ASCIZ /2.computer vs  player  /
 .EVEN
MEPLCO: .ASCIZ /3.player   vs  computer/
 .EVEN
MECOCO: .ASCIZ /4.computer vs  computer/
 .EVEN

;;;erase strings for dead character
CHADEAD:.ASCIZ /                               /
 .EVEN

;;;-----------------------------------------------------------------------------;;;
;;;   MAIN ROUTINE      ;;;
;;;-----------------------------------------------------------------------------;;;

MAIN: JSR PC, INIT
 JSR PC, TURNCHA
 JSR PC, PRIEND
 JSR PC, @#CHIN   ;push any key
 BR MAIN    ;return to first state
 .EOJ

;;;-----------------------------------------------------------------------------;;;
;;;   SUBROTINES      ;;;
;;;-----------------------------------------------------------------------------;;;

;;;----------------initilize-------------------------------------------------------
;;;initilize
INIT: JSR PC, ERALL
 JSR PC, PRIFINF
 JSR PC, CHACHOI
 JSR PC, ERALL
 JSR PC, ERMES
 JSR PC, INITCHA
 JSR PC, DRFRAME
 JSR PC, PRIINF
 JSR PC, PRICDAT
 JSR PC, DRMAP
 JSR PC, DRFACES
 JSR PC, CLRCPOS
 JSR PC, ERACHA
 JSR PC, PRIACHA
 JSR PC, CLRATA
 RTS PC


;;;initilize character data
INITCHA:MOV R5, -(SP)

1$: MOV FISOL(R5), CHASOL(R5)
 MOV FIMORA(R5), CHAMORA(R5)
 MOV FIXPOS(R5), CHAXPOS(R5)
 MOV FIYPOS(R5), CHAYPOS(R5)
 MOV #LIVE, CHALIFE(R5)

 TST (R5)+
 CMP R5, #MAXCHARANUMBER
 BLE 1$

 MOV (SP)+, R5
 RTS PC


;;;erase message on display
ERMES: MOV R0, -(SP)
 MOV R1, -(SP)

 MOV #MESVRAM, R0
 MOV #MESPACE, R1
 JSR PC, PRISTR

 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;character contorol choice
CHACHOI:MOV R0, -(SP)
 MOV R1, -(SP)
 MOV R5, -(SP)

 CLR R5    ;R5 start ID
 MOV #MAXCHARANUMBER, R1  ;R1 end ID

1$: MOV #COMPUTER, CHAMANI(R5)
 TST (R5)+
 CMP R5, R1
 BLE 1$

 CLR R5

2$: JSR PC, @#CHIN
 CMPB R0, #'1   ;both team: player
 BEQ 5$
 CMPB R0, #'2   ;team0:computer, team1:player
 BEQ 3$
 CMPB R0, #'3   ;team0:player, team1:computer
 BEQ 4$
 CMPB R0, #'4   ;both team: computer
 BEQ 6$
 BR 2$

3$: MOV #MAXTEAM0NUMBER, R5
 ADD #2., R5
 BR 5$

4$: MOV #MAXTEAM0NUMBER, R1

5$: MOV #PLAYER, CHAMANI(R5)
 TST (R5)+
 CMP R5, R1
 BLE 5$

6$: MOV (SP)+, R5
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;print first choise of manipulation (computer or player)
PRIFINF:MOV R0, -(SP)
 MOV R1, -(SP)

 MOV #FIRSTMESVRAM, R0
 MOV #MECHOI, R1
 JSR PC, PRISTR

 ADD #VRAMLOOP, R0
 MOV #MEPLPL, R1
 JSR PC, PRISTR

 ADD #VRAMLOOP, R0
 MOV #MECOPL, R1
 JSR PC, PRISTR

 ADD #VRAMLOOP, R0
 MOV #MEPLCO, R1
 JSR PC, PRISTR

 ADD #VRAMLOOP, R0
 MOV #MECOCO, R1
 JSR PC, PRISTR

 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;erase all object and character on display
ERALL: MOV R0, -(SP)

 MOV #VRAM, R0
1$: CLR (R0)+
 CMP R0, #ENDVRAM
 BMI 1$

 JSR R5, @#CLRSCREEN

 MOV (SP)+, R0
 RTS PC
;;;--------------character contorol----------------------------------------
;;;character's turn contorol
TURNCHA:MOV R0, -(SP)
 MOV R1, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R5, -(SP)

 MOV #1.,  R3
 MOV #0., R1
 MOV #16., R2
 CLR R5
 MOV #TURNVRAM, R0
1$: JSR PC, PRITURN
 MOV CHACHAR(R5), (R0)

 TST CHALIFE(R5)   ;character dead or live
 BEQ 3$

 CMP CHAMANI(R5), #PLAYER
 BNE 2$
 
 JSR PC, MOVCHA   ;player contorol
 BR 3$

2$: JSR PC, COMMOV   ;computer contorol

3$: CMP CHALIFE(R1), #DEAD  ;chack each team's captain live or dead
 BEQ 4$
 CMP CHALIFE(R2), #DEAD
 BEQ 4$

 TST (R5)+
 CMP R5, #MAXCHARANUMBER
 BLE 1$
 CLR R5
 INC R3
 BR 1$
 
4$: MOV (SP)+, R5
 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;print turn number on display
;;; param: R3 turn number
PRITURN:MOV R0, -(SP)

 MOV #TURNNUMBERVRAM, R0
 JSR PC, NUMOUT3

 MOV (SP)+, R0
 RTS PC


;;;print end messages
PRIEND: MOV R0, -(SP)
 MOV R1, -(SP)
 MOV R5, -(SP)

 MOV #WINMESVRAM, R0
 MOV #MEWIN, R1

 JSR PC, PRISTR

;print win team's name
 MOV #0., R5

 MOV #MESVRAM, R0
 MOV #TEAM0NAM, R1

 CMP CHALIFE(R5), #DEAD
 BNE 1$
 MOV #TEAM1NAM, R1

1$: JSR PC, PRISTR

 MOV (SP)+, R5
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC



;;;---------print character on map-------------------------------------------------
;;;display all characters
PRIACHA:MOV R5, -(SP)
  
1$: JSR PC, PRI1CHA
 TST (R5)+
 CMP R5, #MAXCHARANUMBER
 BLE 1$

 MOV (SP)+, R5
 RTS PC


;;;display and set CPOS of character
PRI1CHA:MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)
 MOV R5, -(SP)

 TST CHALIFE(R5)   ;check character live or dead
 BEQ 1$
 MOV CHAXPOS(R5), R2
 MOV CHAYPOS(R5), R3
 JSR PC, CAXYTOP

 MOV R5, CPOS(R4)  ;set CPOS(p)
 MOV CHACHAR(R5), VRAM(R4) ;display

1$: MOV (SP)+, R5
 MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 RTS PC


;;;erase all character on display
ERACHA: MOV R4, -(SP)

 CLR R4
1$: CLR VRAM(R4)
 TST (R4)+
 CMP R4, #MAPSIZE
 BMI 1$

 MOV (SP)+, R4
 RTS PC


;;;-------------draw map-----------------------------------------------------------
;;;draw map
;;;p (GEOMAP[p]'s), or x position is given in R3
;;;shift bit number, or y position is given in R2
;;;R4 is geographical data of each GEOMAP[p]
DRMAP: MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)
 MOV R5, -(SP)

 CLR R3    ;now R3 is p
1$: MOV GEOMAP(R3), R4  ;geographical discrimination data is given in R4
 MOV #9.,R2   ;R2 is shift bit number
 MOV R3, -(SP)   ;save p
 ASR R3    ;p * 2
 JSR PC, SHIFTR   ;shift right R4 (R2 bit)
 JSR PC, DIVETEN   ;(x) R3 = R3 % 80. (y) R2 = R3 / 80.   

 JSR PC, MULTEN   ;(x) R3 * 10.
 JSR PC, MULFTEN   ;(y) R2 * 15.

 JSR PC, DRGEO   ;draw fillrect at (x, y)

 MOV (SP)+, R3   ;recover p
 TST (R3)+
 CMP R3, #TWICEMAPSIZE
 BMI 1$

 MOV (SP)+, R5
 MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 RTS PC


;;;draw fillrect at (x, y)
;;;(x, y) = (R3, R2)
;;; param: R3 x pos
;;;  R2 y pos
;;;  R4 geographical distinction number
DRGEO: MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)

 CMP R4, #0.   ;plain
 BEQ 1$
 CMP R4, #1.   ;hill
 BEQ 2$
 CMP R4, #2.   ;load
 BEQ 3$
 CMP R4, #3.   ;river
 BEQ 4$
 CMP R4, #4.   ;wood
 BEQ 5$
 BR 6$

1$: MOV #0, @#7$   ;set color of plain
 MOV #177777, @#7$+2
 MOV #100000, @#7$+4
 BR 6$

2$: MOV #100000, @#7$  ;set color of hill
 MOV #100000, @#7$+2
 MOV #0, @#7$+4
 BR 6$

3$: MOV #170000, @#7$  ;set color of load
 MOV #170000, @#7$+2
 MOV #100000, @#7$+4
 BR 6$

4$: MOV #0, @#7$   ;set color of river
 MOV #0, @#7$+2
 MOV #177777, @#7$+4
 BR 6$

5$: MOV #0, @#7$   ;set color of wood
 MOV #100000, @#7$+2
 MOV #0, @#7$+4
 
6$: JSR R5, @#SETCOLOR
7$: .WORD 0, 0, 0

 MOV R3, @#8$
 MOV R2, @#8$+2
 JSR R5, @#FILLRECT  ;draw fillrect
8$: .WORD 0., 0., 10., 15.   ;fillrect x position, fillrect y position

 MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 RTS PC


;;;----------draw faces------------------------------------------------------------
;;;draw two faces
DRFACES:MOV R0, -(SP)
 MOV R5, -(SP)

 MOV #UEFACE, R5
 MOV #TEAM0FACEXADRESS, R0
 JSR PC, DRFACE
 MOV #TEAM1FACEXADRESS, R0
 MOV #TAFACE, R5
 JSR PC, DRFACE

 MOV (SP)+, R5
 MOV (SP)+, R0
 RTS PC


;;;draw face subroutine
;;; param: R5 top adress of graphic data
;;;  R0 top x adress where user want to draw
DRFACE: MOV R1, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)
 MOV R5, -(SP)

 CLR R1
1$: MOVB (R5)+, R4

 JSR PC, DIV32
 ASL R2
 ASL R3
 ADD #FACEYADRESS, R2
 ADD R0, R3
 JSR PC, DRDOT

 INC R1
 CMPB R4, #DOTEND  ;draw dot until end data appear
 BNE 1$

 MOV (SP)+, R5
 MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R1
 RTS PC


;;;draw fillrect at (x, y)
;;;(x, y) = (R3, R2)
;;; param: R3 x pos
;;;  R2 y pos
;;;  R4 geographical distinction number
DRDOT: MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)

 CMPB R4, #WHI
 BEQ 1$
 CMPB R4, #LGR
 BEQ 2$
 CMPB R4, #DGR
 BEQ 3$
 CMPB R4, #BLK
 BEQ 4$
 CMPB R4, #YEL
 BEQ 5$
 CMPB R4, #BRO
 BEQ 6$
 CMPB R4, #RED
 BEQ 7$
 CMPB R4, #DBL
 BEQ 8$
 CMPB R4, #LPI
 BEQ 9$
 CMPB R4, #GRE
 BEQ 10$
 CMPB R4, #RBR
 BEQ 11$
 CMPB R4, #PBR
 BEQ 12$
 CMPB R4, #LBL
 BEQ 13$

1$: MOV #177777, @#15$
 MOV #177777, @#15$+2
 MOV #177777, @#15$+4
 BR 14$
2$: MOV #100000, @#15$
 MOV #100000, @#15$+2
 MOV #100000, @#15$+4
 BR 14$
3$: MOV #170000, @#15$
 MOV #170000, @#15$+2
 MOV #170000, @#15$+4
 BR 14$
4$: MOV #0, @#15$
 MOV #0, @#15$+2
 MOV #0, @#15$+4
 BR 14$
5$: MOV #177777, @#15$
 MOV #177777, @#15$+2
 MOV #0, @#15$+4
 BR 14$
6$: MOV #177777, @#15$
 MOV #100000, @#15$+2
 MOV #10000, @#15$+4
 BR 14$
7$: MOV #177777, @#15$
 MOV #0, @#15$+2
 MOV #0, @#15$+4
 BR 14$
8$: MOV #0, @#15$
 MOV #100000, @#15$+2
 MOV #177777, @#15$+4
 BR 14$
9$: MOV #177777, @#15$
 MOV #120000, @#15$+2
 MOV #120000, @#15$+4
 BR 14$
10$: MOV #0, @#15$
 MOV #177777, @#15$+2
 MOV #0, @#15$+4
 BR 14$
11$: MOV #130000, @#15$
 MOV #0, @#15$+2
 MOV #0, @#15$+4
 BR 14$
12$: MOV #100000, @#15$
 MOV #10000, @#15$+2
 MOV #10000, @#15$+4
 BR 14$
13$: MOV #0, @#15$
 MOV #170000, @#15$+2
 MOV #177777, @#15$+4

14$: JSR R5, @#SETCOLOR
15$: .WORD 0, 0, 0

 MOV R3, @#16$
 MOV R2, @#16$+2
 JSR R5, @#FILLRECT
16$: .WORD 0, 0, 2, 2

 MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 RTS PC

;;;----------display & print information-------------------------------------------
;;;draw frame at information area
DRFRAME:MOV R5, -(SP)

 JSR R5, @#SETCOLOR  ;draw gray fillrect
 .WORD 60000, 60000, 60000
 JSR R5, @#FILLRECT
 .WORD 0., 240., 800., 15.
 JSR R5, @#SETCOLOR
 .WORD 100000, 100000, 100000
 JSR R5, @#FILLRECT
 .WORD 0., 255., 800., 120.

 JSR R5, @#SETCOLOR  ;draw black lines
 .WORD 0, 0, 0
 JSR R5, @#DRAWLINE
 .WORD 0., 240., 800., 240.
 JSR R5, @#DRAWLINE
 .WORD 0., 255., 800., 255.
 JSR R5, @#DRAWLINE
 .WORD 9., 240., 9., 375.
 JSR R5, @#DRAWLINE
 .WORD 189., 240., 189., 375.
 JSR R5, @#DRAWLINE
 .WORD 209., 240., 209., 375.
 JSR R5, @#DRAWLINE
 .WORD 229., 240., 229., 375.
 JSR R5, @#DRAWLINE
 .WORD 259., 240., 259., 375.
 JSR R5, @#DRAWLINE
 .WORD 319., 240., 319., 375.
 JSR R5, @#DRAWLINE
 .WORD 289., 240., 289., 375.
 JSR R5, @#DRAWLINE
 .WORD 479., 240., 479., 375.
 JSR R5, @#DRAWLINE
 .WORD 489., 240., 489., 375.
 JSR R5, @#DRAWLINE
 .WORD 669., 240., 669., 375.
 JSR R5, @#DRAWLINE
 .WORD 689., 240., 689., 375.
 JSR R5, @#DRAWLINE
 .WORD 709., 240., 709., 799.
 JSR R5, @#DRAWLINE
 .WORD 739., 240., 739., 375.
 JSR R5, @#DRAWLINE
 .WORD 769., 240., 769., 375.
 JSR R5, @#DRAWLINE
 .WORD 799., 240., 799., 375.

 JSR R5, @#FILLRECT
 .WORD 320., 255., 159., 105.

 JSR R5, @#SETCOLOR  ;white fillrect
 .WORD 177777, 177777, 177777
 JSR R5, @#FILLRECT
 .WORD 320., 355., 159., 20.

 MOV (SP)+, R5
 RTS PC


;;;print information name
PRIINF: MOV R0, -(SP)
 MOV R1, -(SP)

 MOV #INFNAMEVRAM, R0
 MOV #INFNAM, R1
 JSR PC, PRISTR
 
 MOV #MESVRAM, R0
 MOV #METURN, R1
 JSR PC, PRISTR

 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;print all character's all data
PRICDAT:MOV R5, -(SP)

 CLR R5
1$: TST CHALIFE(R5)
 BEQ 2$
 JSR PC, PRICCHA
 JSR PC, PRICNAM
 JSR PC, PRICAB
 JSR PC, PRICTYP
 JSR PC, PRICSOL
 JSR PC, PRICMOR
2$: TST (R5)+
 CMP R5, #MAXCHARANUMBER
 BLE 1$

 MOV (SP)+, R5
 RTS PC


;;;set VRAM by team type
;;;ID < MAXTEAM0NUMBER, set R0(VRAM) at left area
;;; param: R5 character's ID
;;; return: R0 VRAM adress
SETVRAM:MOV R5, -(SP)
 
 MOV #CHADATVRAM, R0
 CMP R5, #MAXTEAM0NUMBER
 BLE 1$
 MOV #OTHERCHADATVRAM, R0

1$: MOV (SP)+, R5
 RTS PC


;;;print character's character
;;;check CHATEAM number, print out each team's information area
;;; param: R5 character's ID
PRICCHA:MOV R0, -(SP)
 MOV R5, -(SP)

 JSR PC, SETVRAM
 JSR PC, ADDVRAM

 MOV CHACHAR(R5), (R0)

 MOV (SP)+, R5
 MOV (SP)+, R0
 RTS PC


;;print character's name
;;check CHATEAM number, print out each team's information area
;; param: R5 character's ID
PRICNAM:MOV R0, -(SP)
 MOV R3, -(SP)
 MOV R5, -(SP)

 JSR PC, SETVRAM

 ADD #SHIFTNAMEVRAM, R0
 JSR PC, ADDVRAM
 
 MOV R5, R3
 JSR PC, MULTEN
 JSR PC, PRICN

 MOV (SP)+, R5
 MOV (SP)+, R3
 MOV (SP)+, R0

 RTS PC


;;;print character name at adress (R0)
;;; param: R0 VRAM adress
;;;  R3 pointer for ASCIICODE of character's name
PRICN: MOV R0, -(SP)

 DEC R3    ;before in loop, revice R3
 TST -(R0)   ;before in loop, revice R0
1$: INC R3
 TST (R0)+
 MOVB CHANAME(R3), (R0)
 BNE 1$

 MOV (SP)+, R0
 RTS PC


;;;print out character's attack and defence ability
;;; param: R5 character's ID
PRICAB: MOV R0, -(SP)
 MOV R3, -(SP)
 MOV R5, -(SP)

 JSR PC, SETVRAM

 ADD #SHIFTABVRAM, R0
 JSR PC, ADDVRAM

 MOV CHAATAB(R5), R3 
 JSR PC, NUMOUT2
 ADD #4., R0   ;move VRAM to next information area
 MOV CHADEAB(R5), R3
 JSR PC, NUMOUT2 

 MOV (SP)+, R5
 MOV (SP)+, R3
 MOV (SP)+, R0
 RTS PC


;;;print soldier number
;;; param: R5 character's ID
PRICSOL:MOV R0, -(SP)
 MOV R1, -(SP)
 MOV R3, -(SP)
 MOV R5, -(SP)

 CMP CHALIFE(R5), #LIVE
 BEQ 1$
 JSR PC, SETVRAM
 JSR PC, ADDVRAM
 MOV #CHADEAD, R1
 JSR PC, PRISTR
 BR 2$

1$: JSR PC, SETVRAM

 ADD #SHIFTSOLVRAM, R0
 JSR PC, ADDVRAM

 MOV CHASOL(R5), R3 
 JSR PC, NUMOUT3 

2$: MOV (SP)+, R5
 MOV (SP)+, R3
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;print character morale
;;; param: R5 character's ID
PRICMOR:MOV R0, -(SP)
 MOV R1, -(SP)
 MOV R3, -(SP)
 MOV R5, -(SP)

 CMP CHALIFE(R5), #LIVE
 BEQ 1$
 JSR PC, SETVRAM
 JSR PC, ADDVRAM
 MOV #CHADEAD, R1
 JSR PC, PRISTR
 BR 2$

1$: JSR PC, SETVRAM

 ADD #SHIFTMORVRAM, R0
 JSR PC, ADDVRAM

 MOV CHAMORA(R5), R3 
 JSR PC, NUMOUT3

2$: MOV (SP)+, R5
 MOV (SP)+, R3
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;print character type
;;; param: R5 character's ID
PRICTYP:MOV R0, -(SP)
 MOV R1, -(SP)
 MOV R5, -(SP)

 JSR PC, SETVRAM

 ADD #SHIFTTYPVRAM, R0
 JSR PC, ADDVRAM

 CMP CHATYPE(R5), #KIBA
 BNE 1$
 MOV #CHAKIBA, R1
 BR 3$
1$: CMP CHATYPE(R5), #YARI
 BNE 2$
 MOV #CHAYARI, R1
 BR 3$
2$: MOV #CHATEPO, R1

3$: JSR PC, PRISTR
 
 MOV (SP)+, R5
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;----------get movable area subroutine-------------------------------------------
;;; set all CPOS[p] = #NOCHARACTER
CLRCPOS:MOV R4, -(SP)

 CLR R4
1$: MOV #NOCHARACTER, CPOS(R4)
 TST (R4)+
 CMP R4, #TWICEMAPSIZE
 BMI 1$
 
 MOV (SP)+, R4
 RTS PC


;;;display MPOS[p]
;;;if MPOS[p] = #NOCHECKMPOS, display nothing
;;;if MPOS[p] = 1, 2, ... display "1","2",...
PRIMPOS:MOV R1, -(SP)

 CLR R1
1$: CMP MPOS(R1), #NOCHECKMPOS ;check MPOS[p] == #NOCHECKMPOS
 BEQ 2$    ;if MPOS[p] == #NOCHECKMPOS, do nothing and next p
 ADD #'0, MPOS(R1)  ;else display "MPOS[p]"
 MOV MPOS(R1), VRAM(R1)
 SUB #'0, MPOS(R1)  ;reset MPOS[p]

2$: TST (R1)+
 CMP R1, #TWICEMAPSIZE
 BMI 1$

 MOV (SP)+, R1
 RTS PC


;;;set all MPOS[p] = #NOCHECKMPOS
;;;set all MOABPOS[p] = #0
CLRMPOS:MOV R1, -(SP)

 CLR R1
1$: MOV #NOCHECKMPOS, MPOS(R1)
 CLR MOABPOS(R1)
 TST (R1)+
 CMP R1, #TWICEMAPSIZE
 BMI 1$

 MOV (SP)+, R1
 RTS PC


;;;erase movable information on display
ERMPOS: MOV R1, -(SP)

 CLR R1
1$: CMP MPOS(R1), #NOCHECKMPOS ;if character doesn't exist, not erase
 BEQ 2$
 
 CMP CPOS(R1), #NOCHARACTER ;if character exist, not erase
 BNE 2$
 
 MOV #0, VRAM(R1)
 
2$: TST (R1)+
 CMP R1, #TWICEMAPSIZE
 BMI 1$

 MOV (SP)+, R1
 RTS PC


;;;set character position and move ability,
;;;then call BODMPOS
;;; param: R1 character's move ability
;;;  R5 character's ID
SETMPOS:MOV R0, -(SP)
 MOV R1, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R5, -(SP)

 MOV #FIRSTMPOS, R0
 MOV CHAXPOS(R5), R2
 MOV CHAYPOS(R5), R3

 JSR PC, BODMPOS

 MOV (SP)+, R5
 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;if the position movable, set MPOS[p] = 0, 1, 2,...
;;;this subroutine is main body of MOVABLE
;;; param: R1 character's move ability
;;;  R2 character's x position
;;;  R3 character's y position
BODMPOS:MOV R0, -(SP)   ;save move times
 MOV R1, -(SP)   ;save m
 MOV R2, -(SP)   ;save x
 MOV R3, -(SP)   ;save y
 MOV R4, -(SP)   ;save R4
 MOV CHAMORA(R5), -(SP)  ;save

 CMP R1, #0.   ;check m >= 0
 BMI 5$
 CMP R2, #MINXPOS  ;check x >= 0
 BMI 5$
 CMP R2, #MAXXPOS  ;check x <= 79
 BGT 5$
 CMP R3, #MINYPOS  ;check y >= 0
 BMI 5$
 CMP R3, #MAXYPOS  ;check y <= 15
 BGT 5$
 JSR PC, CAXYTOP   ;p = 2 * ( x + y * 80. )

 JSR PC, SUBMORA   ;character's morale - (comsumption / 4)
 TST CHAMORA(R5)
 BLE 5$    ;if character's morale  <= 0, serch end

 CMP CPOS(R4), #NOCHARACTER ;if character is not exist
 BNE 1$    ;serch continiue
 BR 2$
1$: CMP CPOS(R4), R5  ;if character's ID on map == R5
 BNE 5$    ;serch continiue

2$: INC R0    ;culcurate minimum distance
 CMP R0, MPOS(R4)
 BMI 3$

 CMP R1, MOABPOS(R4)
 BMI 5$
3$: MOV R1, MOABPOS(R4)

 MOV R0, MPOS(R4)  ;set MPOS[p] = R0
 JSR PC, SUBCOMS

 DEC R2    ;Case BODMPOS(m-1,x-1,y)
 JSR PC, BODMPOS
 INC R2

 DEC R3    ;Case BODMPOS(m-1,x,y-1)
 JSR PC, BODMPOS
 INC R3

 INC R2    ;Case BODMPOS(m-1,x+1,y)
 JSR PC, BODMPOS
 DEC R2

 INC R3    ;Case BODMPOS(m-1,x,y+1)
 JSR PC, BODMPOS
 DEC R3

5$: MOV (SP)+, CHAMORA(R5)

 MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;----------character contorol subroutines by player------------------------------
;;;print fillrect at information area
;;; param: R5 character ID number
PRILAMI:MOV R0, -(SP)
 MOV R5, -(SP)

 MOV #INFTEAM0XVRAM, @#2$
 CMP R5, #MAXTEAM0NUMBER
 BLE 1$
 MOV #INFTEAM1XVRAM, @#2$
1$: MOV #INFAREAYVRAM, R0

 JSR PC, ADDDRAW

 MOV R0, @#2$+2

 JSR R5, @#FILLRECT
2$: .WORD 0., 0., 9., 15.

 MOV (SP)+, R5
 MOV (SP)+, R0
 RTS PC


;;;print fillrect at map area
;;; param: R5 character ID number
PRILAMM:MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R5, -(SP)

 MOV CHAXPOS(R5), R3  ;x position
 JSR PC, MULTEN
 MOV R3, @#1$

 MOV CHAYPOS(R5), R2  ;y position
 JSR PC, MULFTEN
 MOV R2, @#1$+2

 JSR R5, FILLARCT
1$: .WORD 0., 0., 9., 14., 0., 55000

 MOV (SP)+, R5
 MOV (SP)+, R3
 MOV (SP)+, R2
 RTS PC


;;;print map graphic at the position of character whose ID is R5
;;; param: R5 character ID number
ERLAMM: MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)
 MOV R5, -(SP)

 MOV CHAXPOS(R5), R2
 MOV CHAYPOS(R5), R3
 JSR PC, CAXYTOP
 MOV GEOMAP(R4), R4
 MOV #9., R2   ;R2 is shift bit number
 JSR PC, SHIFTR   ;shift right R4 (R2 bit)
 MOV CHAXPOS(R5), R3
 JSR PC, MULTEN
 MOV CHAYPOS(R5), R2
 JSR PC, MULFTEN
 JSR PC, DRGEO

 MOV (SP)+, R5
 MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 RTS PC


;;;character's move phase contorol
MOVCHA: MOV R0, -(SP)
 MOV R1, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)
 MOV R5, -(SP)

 JSR R5, @#SETCOLOR
 .WORD 0, 140000, 177777

 JSR PC, PRILAMI   ;print FILLRECT at information area

 MOV CHAXPOS(R5), -(SP)  ;-------------------------------------
 MOV CHAYPOS(R5), -(SP)  ;save state because of cancel command
 MOV CHAMORA(R5), -(SP)  ;
 MOV CHAMOAB(R5), R1  ;-------------------------------------
 
1$: MOV CHAXPOS(R5), R2
 MOV CHAYPOS(R5), R3
 JSR PC, CAXYTOP
 MOV R5, CPOS(R4)

 JSR R5, @#SETCOLOR
 .WORD 0, 140000, 177777
 JSR PC, PRILAMM   ;print fillrect at map area

 JSR PC, CLRMPOS   ;-------------------------------------
 JSR PC, SETMPOS   ;serch movable area and print
 JSR PC, PRIMPOS   ;
 JSR PC, PRI1CHA   ;-------------------------------------

 JSR PC, PRICMOR   ;print morale

 JSR PC, ERATA   ;-------------------------------------
 JSR PC, CLRATA   ;serch enemy which can be attacked
 JSR PC, SERATA   ;and print lamp at the enemy
 JSR PC, PRIATA   ;-------------------------------------
 
2$: JSR PC, @#CHIN
 JSR PC, ERLAMM
 JSR PC, ERMPOS

 CMPB #'4, R0   ;character go left
 BEQ 3$
 CMPB #'6, R0   ;character go right
 BEQ 4$
 CMPB #'8, R0   ;character go up
 BEQ 5$
 CMPB #'2, R0   ;character go down
 BEQ 6$
 CMPB #'5, R0   ;move cancel and locate the character
 BEQ 7$    ;on the first position
 CMPB #'0, R0   ;end move
 BEQ 8$
 BR 9$

3$: JSR PC, LEFTMOV   ;left move
 BR 1$

4$: JSR PC, RIGHMOV   ;right move
 BR 1$

5$: JSR PC, UPMOV   ;up move
 BR 1$

6$: JSR PC, DOWNMOV   ;down move
 BR 1$

7$: MOV 4(SP), CHAXPOS(R5)  ;move cancel, return the state before move
 MOV 2(SP), CHAYPOS(R5)
 MOV (SP), CHAMORA(R5)
 MOV CHAMOAB(R5), R1
 MOV #NOCHARACTER, CPOS(R4)
 MOV #0, VRAM(R4)
 BR 1$

8$: JSR PC, ENDMOV   ;move end and turn next character
 BR 10$    ;morale is up when this command execute

9$: JSR PC, ATTACK
 CMP R0, #NOTATTACKEXECUTE ;if player doesn't execute attack, branch 1$
 BEQ 1$

10$: JSR PC, ERATA
 JSR R5, @#SETCOLOR
 .WORD 100000, 100000, 100000
 JSR PC, PRILAMI   ;print gray fillrect at information area
 ADD #6., SP

 MOV (SP)+, R5
 MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;character left move
;;; param: R2 character x position
;;;  R5 character's ID
LEFTMOV:MOV R0, -(SP)
 MOV R2, -(SP)

 CMP R2, #MINXPOS
 BEQ 1$

 MOV R4, R0
 SUB #2., R0
 CMP MPOS(R0), #NOCHECKMPOS
 BEQ 1$

 DEC CHAXPOS(R5)
 JSR PC, AFTRMOV

1$: MOV (SP)+, R2
 MOV (SP)+, R0
 RTS PC


;;;character right move
;;; param: R2 character x position
;;;  R5 character's ID
RIGHMOV:MOV R0, -(SP)
 MOV R2, -(SP)

 CMP R2, #MAXXPOS  ;if CHAPOSX ==79., do nothing
 BEQ 1$

 MOV R4, R0 
 ADD #2., R0
 CMP MPOS(R0), #NOCHECKMPOS ;if MPOS[p] == 0, do nothing
 BEQ 1$

 INC CHAXPOS(R5)
 JSR PC, AFTRMOV

1$: MOV (SP)+, R2
 MOV (SP)+, R0
 RTS PC


;;;character up move
;;; param: R3 character y position
;;;  R5 character's ID
UPMOV: MOV R0, -(SP)
 MOV R3, -(SP)

 CMP R3, #MINYPOS  ;if CHAYPOS== 0., do nothing
 BEQ 1$

 MOV R4, R0
 SUB #160., R0
 CMP MPOS(R0), #NOCHECKMPOS ;if MPOS[p] == 0, do nothing
 BEQ 1$

 DEC CHAYPOS(R5)
 JSR PC, AFTRMOV

1$: MOV (SP)+, R3
 MOV (SP)+, R0
 RTS PC


;;;character down move
;;; param: R3 character y position
;;;  R5 character's ID
DOWNMOV:MOV R0, -(SP)
 MOV R3, -(SP)

 CMP R3, #MAXYPOS  ;if CHAYPOS == 15., do nothing
 BEQ 1$
 
 MOV R4, R0
 ADD #160., R0
 CMP MPOS(R0), #NOCHECKMPOS ;if MPOS[p] == 0, do nothing
 BEQ 1$

 INC CHAYPOS(R5)
 JSR PC, AFTRMOV

1$: MOV (SP)+, R3
 MOV (SP)+, R0
 RTS PC


;;;after character move
;;; param: R4 position
AFTRMOV:JSR PC, SUBCOMS
 JSR PC, SUBMORA
 MOV #NOCHARACTER, CPOS(R4)
 MOV #0, VRAM(R4)
 RTS PC


;;;move end
;;; param: R5 character's ID
ENDMOV: MOV R0, -(SP)
 MOV R5, -(SP)
 
 MOV CHAATAB(R5), R0
 ADD CHADEAB(R5), R0
 ASL R0
 ADD #7., R0
 ASR R0
 ASR R0
 ASR R0
 ADD R0, CHAMORA(R5)
 CMP CHAMORA(R5), #MAXMORALE ;chack character morale =< 120.
 BLE 1$
 MOV #MAXMORALE, CHAMORA(R5)
1$: JSR PC, PRICMOR

 MOV (SP)+, R5
 MOV (SP)+, R0
 RTS PC


;;;--------character contorol subroutines by computer------------------------------
;;;computer move contorol
;;; param: R5 character's ID
COMMOV: MOV R0, -(SP)
 MOV R1, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)
 MOV R5, -(SP)

 JSR R5, @#SETCOLOR
 .WORD 0, 140000, 177777

 JSR PC, PRILAMI   ;print FILLRECT at information area

 MOV CHAMOAB(R5), R1  ;value of R1 can be discarded
 JSR PC, CLRMPOS
 JSR PC, SETMPOS
 JSR PC, NEARPOS
 JSR PC, SERROUT   ;R2 is stack pointer

 CLR R3    ;R3 is move times

1$: JSR PC, COMMSET   ;set data before move

 MOV (R2)+, R0   ;pop the route data
 JSR PC, ERLAMM   ;erase lamp on map

 TST R3    ;if move times == 0, not execute attack command
 BNE 7$
 CMP R0, #COMMOVEND  ;if ( move times == 0 && character can't move )
 BNE 8$    ;attack execute

7$: JSR PC, COMATA
 CMP R1, #MAXCHARANUMBER  ;if attack is not executed, character move
 BLE 6$

8$: INC R3    ;incliment move times
 CMP R0, #COMRIGHTMOV
 BEQ 2$
 CMP R0, #COMLEFTMOV
 BEQ 3$
 CMP R0, #COMDOWNMOV
 BEQ 4$
 CMP R0, #COMUPMOV
 BEQ 5$
 CMP R0, #COMMOVEND
 BEQ 6$

2$: JSR PC, RIGHMOV
 BR 1$

3$: JSR PC, LEFTMOV
 BR 1$

4$: JSR PC, DOWNMOV
 BR 1$

5$: JSR PC, UPMOV
 BR 1$

6$: JSR PC, ENDMOV
 JSR PC, ERLAMM   ;erase lamp on map
 JSR R5, @#SETCOLOR
 .WORD 100000, 100000, 100000
 JSR PC, PRILAMI   ;erase lamp at information area

 MOV (SP)+, R5
 MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;character data set before move
;;; param: R5 character ID number
;;; return: R4 character position
COMMSET:MOV R2, -(SP)   ;save R2
 MOV R3, -(SP)

 MOV CHAXPOS(R5), R2
 MOV CHAYPOS(R5), R3
 JSR PC, CAXYTOP
 MOV R5, CPOS(R4)

 JSR R5, @#SETCOLOR
 .WORD 0, 140000, 177777
 JSR PC, PRILAMM   ;print FILLARCT at map area

 JSR PC, PRI1CHA   ;print 1character
 JSR PC, PRICMOR   ;print morale
 JSR PC, CLRATA   ;clear all attack frag
 JSR PC, SERATA   ;serch enemy character which can be attacked

 MOV (SP)+, R3
 MOV (SP)+, R2
 RTS PC


;;;serch the nearest position toward enemy captain
;;;return the value of the position
;;; return: R0 nearest position of enemy
NEARPOS:MOV R1, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)

 MOV #16., R1   ;team1 captain
 TST CHATEAM(R5)
 BEQ 1$
 MOV #0., R1   ;team0 captain

1$: MOV #CHANOTMOVE, R0  ;character don't move
 CLR R4
 MOV #MAXDISTANCE, R3  ;R3 is minimum distance, now set first value
2$: CMP MPOS(R4), #NOCHECKMPOS ;if position is not movable, not compare
 BEQ 3$

 TST MPOS(R4)   ;the position where character now exist
 BEQ 3$    ;not compare

 JSR PC, CULDIST
 CMP R2, R3   ;compare culclate distance and minimum distance
 BGT 3$

 MOV R2, R3   ;if culclate distance < minimum distance,
 MOV R4, R0   ;set this position

3$: TST (R4)+
 CMP R4, #TWICEMAPSIZE
 BMI 2$

 CMP R0, #CHANOTMOVE  ;if character can't move,
 BNE 4$    ;set the position where character now exist
 MOV CHAXPOS(R5), R2
 MOV CHAYPOS(R5), R3
 JSR PC, CAXYTOP
 MOV R4, R0

4$: MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R1
 RTS PC


;;;culculate the distance
;;; param: R4 positon
;;;  R1 character ID number
;;; return: R2 distance
CULDIST:MOV R1, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)
 MOV R5, -(SP)

 MOV R4, R3
 ASR R3
 JSR PC, DIVETEN   ;( R2, R3 ) = ( x, y )

 SUB CHAYPOS(R1), R2
 JSR PC, ABSR2   ;x distance
 MOV R2, -(SP)   ;save x distance value

 MOV R3, R2
 SUB CHAXPOS(R1), R2
 JSR PC, ABSR2   ;y distance
 ADD (SP)+, R2   ;sum distance

 MOV (SP)+, R5
 MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R1
 RTS PC


;;;serch the route from final purpose position
;;;and pop the route data at #CROUTE
;;;R2 is stack pointer
;;; param: R0 purpose position
;;; return: R2 stack pointer
SERROUT:MOV R0, -(SP)
 MOV R1, -(SP)

 MOV #CROUTE, R2   ;set R2 (stack pointer) at #CROUTE+2
 ADD #COMROUTESIZE+2, R2  ;
 MOV #COMMOVEND, -(R2)  ;pop end move data

 MOV MPOS(R0), R1
1$: TST R1
 BEQ 6$
 DEC R1

 SUB #2., R0   ;left
 CMP R1, MPOS(R0)
 BEQ 2$
 ADD #4., R0   ;right
 CMP R1, MPOS(R0)
 BEQ 3$
 SUB #162., R0   ;up
 CMP R1, MPOS(R0)
 BEQ 4$
 ADD #320., R0   ;down
 CMP R1, MPOS(R0)
 BEQ 5$
 BR 2$

2$: MOV #COMRIGHTMOV, -(R2)
 BR 1$
3$: MOV #COMLEFTMOV, -(R2)
 BR 1$
4$: MOV #COMDOWNMOV, -(R2)
 BR 1$
5$: MOV #COMUPMOV, -(R2)
 BR 1$

6$: MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;character's moveability - GEOMAP[p]'s comsumption data
;;; param: R1 rest of move ability
;;;  R4 GEOMAP[p]'s p
;;; return: R1 move ability after move
SUBCOMS:MOV R0, -(SP)
 MOV R4, -(SP)
 
 MOV GEOMAP(R4), R0
 BIC #7770, R0   ;get the each GEOMAP[p]'s
 SUB R0, R1   ; comsumption data of move ability

 MOV (SP)+, R4
 MOV (SP)+, R0
 RTS PC

;;;character's morale - (geographical comsumption / 2)
;;; param: R5 character's ID
;;;  R4 GEOMAP[p]'s p
SUBMORA:MOV R0, -(SP)
 MOV R4, -(SP)
 
 MOV GEOMAP(R4), R0
 BIC #7770, R0
 ASR R0
 SUB R0, CHAMORA(R5)

 MOV (SP)+, R4
 MOV (SP)+, R0
 RTS PC


;;;----------subroutines which is concerned with attack----------------------------
;;;computer attack subroutine
;;;if chracter which can be attacked exists, attack execute
;;;search enemy from small number
;;; param: R5 character ID number
COMATA: MOV R5, -(SP)

 CLR R1

1$: TST CHAATBL(R1)
 BEQ 4$

 JSR PC, DRIAECT
 CMP CHATYPE(R5), #TEPPOU ;check chracter type
 BNE 2$    ;if type is TEPPOU, execute SUBGATA
 JSR PC, SUBGATA
 BR 3$

2$: JSR PC, SUBIATA
3$: JSR PC, SUBIMOR

 JSR PC, JUDLIDE   ;judge enemy character live or dead

 MOV R1, -(SP)
 MOV R5, R1
 JSR PC, JUDLIDE   ;judge turn character live or dead
 MOV (SP)+, R1

 JSR PC, PRICSOL
 JSR PC, PRICMOR   ;print turn character information

 MOV R5, -(SP)   ;save R5
 MOV R1, R5
 JSR PC, PRICSOL   ;print enemy character information
 JSR PC, PRICMOR
 MOV (SP)+, R5   ;recover R5
 BR 5$    ;attack is executed, break

4$: TST (R1)+
 CMP R1, #MAXCHARANUMBER
 BLE 1$

5$: MOV (SP)+, R5
 RTS PC


;;;culclate fundamental damage which is given to enemy
;;;if this subroutine is called, the value of R4 is broken
;;; param: R1 enemy character ID number
;;;  R5 character ID number
;;; return: R4 answer of dammage
CULDAMG:MOV R0, -(SP)
 MOV R1, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R5, -(SP)

 MOV CHADEAB(R1), R0  ;enemy character defence ability
 MOV CHAXPOS(R1), R2  ;enemy character x position
 MOV CHAYPOS(R1), R3  ;enemy character y position

 JSR PC, CAXYTOP   ;get enemy character GEOMAP[p]'s p
 MOV GEOMAP(R4), R4
 ASR R4
 ASR R4
 ASR R4
 BIC #770, R4   ;get enemy character's geographical defence effect
 ADD R4, R0   ;R0 has value of "defence + geographical effect"
 
 MOV R0, -(SP)   ;save R0
 MOV CHAATAB(R5), R0  ;character attack ability
 MOV CHAXPOS(R5), R2  ;character x position
 MOV CHAYPOS(R5), R3  ;character y position
 JSR PC, CAXYTOP
 MOV GEOMAP(R4), R4  ;get enemy character GEOMAP[p]'s p
 ASR R4
 ASR R4
 ASR R4
 ASR R4
 ASR R4
 ASR R4
 BIC #70, R4   ;get character's geographical attack effect
 ADD R4, R0
 ASL R0
 ASL R0
 ADD #40., R0   ;R0 = "(attack + geographical effect) * 4 + 40."
 SUB (SP)+, R0   ;R0 ="{(attack + geographical effect) * 4 + 40.}
     ;-{defence + geographical effect}"
 MOV R0, R2   ;calculate the square of R0

 MOV R0, R3
 MOV R1, -(SP)   ;save R1 (enemy ID number)
 JSR PC, MULFAST
 MOV R1, R0   ;answer is given in R0
 MOV (SP)+, R1   ;recover R1 (enemy ID number)
 
 ASR R0
 ASR R0
 ASR R0
 ASR R0
 ASR R0
 ASR R0
 ASR R0    ;R0 / 128.

 MOV CHASOL(R5), R2
 ADD #256., R2
 ASR R2
 ASR R2
 ASR R2
 ASR R2
 ASR R2    ;R2 = (soldier + 256.) / 32.

 MOV CHAMORA(R5), R3
 ADD #32., R3
 ASR R3
 ASR R3
 ASR R3
 ASR R3    ;R3 = (morale + 32.) / 16.

 MOV R1, -(SP)   ;save R1
 JSR PC, MULFAST
 MOV R1, R2
 MOV (SP)+, R1   ;recover R1
 ASR R2    ;R2 = R2 * R3

 MOV R0, R3
 JSR PC, MULFAST
 MOV R1, R4
 ASR R4
 ASR R4
 ASR R4
 ASR R4
 ASR R4
 ASR R4    ;answer is given in R4

 MOV (SP)+, R5
 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;CHASOL(R1) - (damage by fire)
;;;damage changes by distance between turn character and enemy character
;;; param: R1 enemy character ID
;;;  R5 turn character ID
SUBGATA:MOV R1, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)

 MOV CHAXPOS(R5), R2
 MOV CHAXPOS(R1), R3
 SUB R3, R2
 JSR PC, ABSR2   ;culculate x distance
 MOV R2, -(SP)

 MOV CHAYPOS(R5), R2
 MOV CHAYPOS(R1), R3
 SUB R3, R2
 JSR PC, ABSR2   ;culculate y distance
 ADD (SP)+, R2   ;sum distance

 JSR PC, CULDAMG
 JSR PC, SHIFTR   ;damage / 2 (R2 times)
 SUB R4, CHASOL(R1)

;character soldier and morale < 0, set these values = 0
 TST CHASOL(R1)
 BGT 1$
 MOV #0., CHASOL(R1)
 BR 2$
1$: TST CHAMORA(R1)
 BGT 2$
 MOV #0., CHAMORA(R1)

2$: MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R1
 RTS PC


;;;CHASOL(R1) - (damage by immediate attack)
;;;CHASOL(R5) - (damage by immediate attack)
;;; param: R1 defence character ID
;;;  R5 attack character ID
SUBIATA:MOV R1, -(SP)
 MOV R4, -(SP)

;CHASOL(R1) - (damage by immediate attack)
 JSR PC, CULDAMG
 SUB R4, CHASOL(R1)

;character soldier and morale < 0, set these values = 0
 TST CHASOL(R1)
 BGT 1$
 MOV #0., CHASOL(R1)
 BR 4$
1$: TST CHAMORA(R1)
 BGT 2$
 MOV #0., CHAMORA(R1)
 BR 4$

;CHASOL(R5) - (damage by immediate attack)
2$: MOV R5, -(SP)   ;exchange R1 and R5
 MOV R1, R5
 MOV (SP)+, R1

 JSR PC, CULDAMG
 ASR R4    ;damage / 2

 MOV R5, -(SP)   ;exchange R1 and R5
 MOV R1, R5
 MOV (SP)+, R1

;character soldier and morale < 0, set these values = 0
 SUB R4, CHASOL(R5)
 TST CHASOL(R5)
 BGT 3$
 MOV #0., CHASOL(R5)
 BR 4$
3$: TST CHAMORA(R5)
 BGT 4$
 MOV #0., CHAMORA(R5)

4$: MOV (SP)+, R4
 MOV (SP)+, R1
 RTS PC


;;; sub enemy morale
SUBIMOR:MOV R0, -(SP)
 MOV R1, -(SP)
 MOV R5, -(SP)
 
 MOV CHAATAB(R5), R0
 ASL R0
 SUB CHADEAB(R1), R0
 ASR R0
 ASR R0
 BGT 1$
 CLR R0
 
1$: SUB R0, CHAMORA(R1)
 TST CHAMORA(R1)
 BGT 2$
 MOV #0., CHAMORA(R1)

2$: MOV (SP)+, R5
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;attack subroutine
;;; param: R0 enemy character's character
;;;  R5 character's ID
;;; return: R0 if attack is executed, return character ID,
;;;     else,     return #NOTATTACKEXECUTE
ATTACK: MOV R1, -(SP)
 MOV R5, -(SP)

 CLR R1
 TST CHATEAM(R5)   ;if CHATEAM(R5) == 1, R0 - 40
 BEQ 2$
 SUB #40, R0

2$: CMPB CHACHAR(R1), R0
 BEQ 3$
 ADD #2., R1
 CMP R1, #MAXCHARANUMBER
 BLE 2$
 MOV #NOTATTACKEXECUTE, R0
 BR 7$

3$: TST CHAATBL(R1)
 BNE 4$
 MOV #NOTATTACKEXECUTE, R0
 BR 7$

4$: JSR PC, DRIAECT
 CMP CHATYPE(R5), #TEPPOU
 BNE 5$
 JSR PC, SUBGATA
 BR 6$

5$: JSR PC, SUBIATA
6$: JSR PC, SUBIMOR

 JSR PC, JUDLIDE

 MOV R1, -(SP)
 MOV R5, R1
 JSR PC, JUDLIDE
 MOV (SP)+, R1

 JSR PC, PRICSOL
  JSR PC, PRICMOR

 MOV R5, -(SP)   ; save R5
 MOV R1, R5
 JSR PC, PRICSOL   ; print enemy character information
 JSR PC, PRICMOR   ; print enemy character information
 MOV (SP)+, R5   ; recover R5

7$: MOV (SP)+, R5
 MOV (SP)+, R1
 RTS PC


;;;print the mark at the enamy which can be attacked
;;; param: R5 character's ID
;;;  R1 character's ID (being attacked)
PRIATA: MOV R1, -(SP)
 MOV R5, -(SP)

 JSR R5, @#SETCOLOR
 .WORD 177777, 100000, 0  ;set color orange

 CLR R1
1$: TST CHAATBL(R1)
 BEQ 2$

 MOV R1, R5
 JSR PC, PRILAMM
 JSR PC, PRILAMI

2$: ADD #2., R1   ;get next character ID
 CMP R1, #MAXCHARANUMBER
 BLE 1$

 MOV (SP)+, R5
 MOV (SP)+, R1
 RTS PC


;;;serch the enemy which can be attacked
;;; param: R5 character ID
SERATA: MOV R1, -(SP)

 MOV #YARI, R1
 CMP CHATYPE(R5), #TEPPOU
 BNE 1$
 MOV #TEPPOU, R1

1$: JSR PC, SERABOD

 MOV (SP)+, R1
 RTS PC

;;;serch the enemy which can be attacked
;;;maim routine
;;; param: R1 attack possible area size
;;;  R2 x position
;;;  R3 y posituon
SERABOD:MOV R1, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)

 CMP R1, #0.   ;check attackable squer number >= 0
 BMI 1$
 CMP R2, #MINXPOS  ;check x >= 0
 BMI 1$
 CMP R2, #MAXXPOS  ;check x <= 79
 BGT 1$
 CMP R3, #MINYPOS  ;check y >= 0
 BMI 1$
 CMP R3, #MAXYPOS  ;check y <= 15
 BGT 1$
 JSR PC, CAXYTOP   ;p = 2 * ( x + y * 80. )

 JSR PC, GETATID
 DEC R1

 DEC R2    ;Case BODMPOS(m-1,x-1,y)
 JSR PC, SERABOD
 INC R2

 DEC R3    ;Case BODMPOS(m-1,x,y-1)
 JSR PC, SERABOD
 INC R3

 INC R2    ;Case BODMPOS(m-1,x+1,y)
 JSR PC, SERABOD
 DEC R2

 INC R3    ;Case BODMPOS(m-1,x,y+1)
 JSR PC, SERABOD
 DEC R3

1$: MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R1
 RTS PC


;;;if the enemy which can be attacked exists, CHAATBL(R1) = 1
;;;eles do nothing
GETATID:MOV R1, -(SP)
 CMP CPOS(R4), #NOCHARACTER
 BEQ 1$
 MOV CPOS(R4), R1  ;character's ID
 CMP CHATEAM(R5), CHATEAM(R1)
 BEQ 1$
 MOV #1., CHAATBL(R1)
1$: MOV (SP)+, R1
 RTS PC
 
 
;;;clear each character's attackable flag
CLRATA: MOV R1, -(SP)
 
 CLR R1
1$: CLR CHAATBL(R1)
 TST (R1)+
 CMP R1, #MAXCHARANUMBER
 BLE 1$

 MOV (SP)+, R1
 RTS PC


;;;erase the lamp of attackable character
ERATA: MOV R1, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)
 MOV R5, -(SP)

 CLR R1
1$: TST CHAATBL(R1)
 BEQ 2$

 MOV R1, R5
 JSR PC, ERLAMM

 JSR R5, @#SETCOLOR
 .WORD 100000, 100000, 100000
 JSR PC, PRILAMI

2$: ADD #2., R1
 CMP R1, #MAXCHARANUMBER
 BLE 1$

 MOV (SP)+, R5
 MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R1
 RTS PC


;;;draw graffic effect of attack
DRIAECT:MOV R0, -(SP)
 MOV R1, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)
 MOV R5, -(SP)

 MOV #INFTEAM0XVRAM, @#4$ ;effect on information area
 MOV #INFTEAM0XVRAM, @#5$ ;x position
 MOV #INFTEAM0XVRAM, @#7$

 CMP R1, #MAXTEAM0NUMBER  ;check team
 BLE 1$
 MOV #INFTEAM1XVRAM, @#4$ ;effect on information area
 MOV #INFTEAM1XVRAM, @#5$ ;x position
 MOV #INFTEAM1XVRAM, @#7$
1$: MOV #INFAREAYVRAM, R0

 MOV R1, R5
 JSR PC, ADDDRAW

 MOV R0, @#4$+2   ;effect on information area
 MOV R0, @#5$+2   ;y position
 MOV R0, @#7$+2

 MOV CHAXPOS(R1), R3  ;enemy character effect 
 JSR PC, MULTEN
 MOV R3, @#3$
 MOV R3, @#6$

 MOV CHAYPOS(R1), R2
 JSR PC, MULFTEN
 MOV R2, @#3$+2
 MOV R2, @#6$+2
 
 MOV #100., R4   ;R4 is loop number

2$: JSR R5, @#SETCOLOR  ;set color red
 .WORD 177777, 0, 0

 JSR R5, @#FILLARCT  ;draw red fillarct
3$: .WORD 0., 0., 10., 15., 0, 55000

 JSR R5, @#FILLRECT  ;draw red fillrect
4$: .WORD 0., 0., 189., 15.

 JSR R5, @#SETCOLOR  ;set color white
 .WORD 177777, 177777, 177777
 
 JSR R5, @#FILLRECT  ;draw white fillrect
5$: .WORD 0., 0., 189., 15.

 JSR R5, @#FILLARCT  ;draw white fillarct
6$: .WORD 0., 0., 10., 15., 0, 55000

 DEC R4
 TST R4
 BNE 2$

 JSR R5, @#SETCOLOR  ;set color light gray
 .WORD 100000, 100000, 100000
 JSR R5, @#FILLRECT
7$: .WORD 0., 0., 189., 15.

 MOV R1, R5   ;print map graphic at the position of
 JSR PC, ERLAMM   ;character whose ID is R1

 JSR R5, @#SETCOLOR  ;set color black
 .WORD 0, 0, 0
 JSR R5, @#DRAWLINE  ;draw lines at information area
 .WORD 9., 240., 9., 375.
 JSR R5, @#DRAWLINE
 .WORD 489., 240., 489., 375.

 MOV (SP)+, R5
 MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;judge character live or dead
;;; param: R1 character ID
;;;  R4 position number
JUDLIDE:MOV R0, -(SP)
 MOV R1, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)
 MOV R4, -(SP)

 TST CHASOL(R1)   ;check morale or soldier == 0
 BLE 1$
 TST CHAMORA(R1)
 BLE 1$
 BR 2$

1$: MOV #DEAD, CHALIFE(R1)  ;set character dead
 MOV CHAXPOS(R1), R2
 MOV CHAYPOS(R1), R3
 JSR PC, CAXYTOP
 MOV #NOCHARACTER, CPOS(R4) ;clear character data on CPOS
 MOV #40, VRAM(R4)  ;erase character's character on map

2$: MOV (SP)+, R4
 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;----------multipurpose subloutines----------------------------------------------
;;;change (x,y) to p (POS[p]'s)
;;;R4 = 2 * ( R2 + R3 * 80. )
;;; p = 2 * ( x +  y * 80. )
;;; param: R2 x position
;;;  R3 y position
;;; return R4
CAXYTOP:MOV R2, -(SP)
 MOV R3, -(SP)

 ASL R3    ;y * 2.
 ASL R3    ;y * 4.
 ASL R3    ;y * 8.
 JSR PC, MULTEN   ;y * 80.
 ADD R2, R3
 MOV R3, R4
 ASL R4

 MOV (SP)+, R3
 MOV (SP)+, R2
 RTS PC


;;;R2 = R3 / 10.
;;;R3 = R3 % 10.
;;; param: R3 dividend
;;; return: R2 quotient
;;;  R3 remainder
DIVTEN: CLR R2
1$: SUB #10., R3
 BMI 2$
 INC R2
 BR 1$
2$: ADD #10., R3
 RTS PC


;;;(y) R2 = R1 / 32.
;;;(x) R3 = R1 % 32.
;;; param: R1 dividend
;;; return: R2 quotient
;;;  R3 remainder
DIV32: MOV R1, -(SP)

 MOV R1, R2
 ASR R2
 ASR R2
 ASR R2
 ASR R2
 ASR R2

 MOV R2, R3
 ASL R3
 ASL R3
 ASL R3
 ASL R3
 ASL R3

 SUB R3, R1
 MOV R1, R3

 MOV (SP)+, R1
 RTS PC


;;;(y) R2 = R3 / 80.
;;;(x) R3 = R3 % 80.
;;; param: R3 dividend
;;; return: R2 quotient
;;;  R3 remainder
DIVETEN:CLR R2
1$: SUB #80., R3
 BMI 2$
 INC R2
 BR 1$
2$: ADD #80., R3
 RTS PC


;;R2 = R3 / 100.
;;R3 = R3 % 100.
;; param: R3 dividend
;; return: R2 quotient
;;  R3 remainder
DIVHUND:CLR R2
1$: SUB #100., R3
 BMI 2$
 INC R2
 BR 1$
2$: ADD #100., R3
 RTS PC


;;; fast multiply subroutine
;;; R1 = R2 * R3
;;; param: R2
;;;   R3
;;; return: R1 answer
MULFAST:MOV R2, -(SP)
 MOV R3, -(SP)
 
 CLR R1
1$: BIT #1, R2
 BEQ 2$
 ADD R3, R1
 
2$: ASL R3
 ASR R2
 TST R2
 BNE 1$

 MOV (SP)+, R3
 MOV (SP)+, R2
 RTS PC


;;;R3 = R3 * 10.
;;; param: R3
;;; return: R3
MULTEN: MOV R4, -(SP)

 MOV R3, R4
 ASL R4
 ASL R4
 ADD R3, R4
 ASL R4
 MOV R4, R3

 MOV (SP)+, R4
 RTS PC


;;;R2 = R2 * 15.
;;; param: R2
;;; return: R2
MULFTEN:MOV R4, -(SP)   ;save R4

 MOV R2, R4
 ASL R2
 ASL R2
 ASL R2
 ASL R2
 SUB R4, R2

 MOV (SP)+, R4   ;recover R4
 RTS PC


;;;R4 = shift right R4 (R2 bit)
;;; param: R4 source of number
;;;  R2 shift bit number
;;; return: R4 number after shift right
SHIFTR :ASR R4
 DEC R2
 BGT SHIFTR
 RTS PC


;;print the value of R2(1digit number) to (R0)
;; param: R0 moniter routine adress
;;  R2 the value of each digit
PRIDIGT:MOV R2, -(SP)

 ADD #'0, R2
 MOV R2, (R0)+

 MOV (SP)+, R2
 RTS PC


;;;print 2digit number of R3 from adress (R0)
;;; param: R3 number which you want to print
;;;  R0 VRAM adress
NUMOUT2:MOV R0, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)

 JSR PC, DIVTEN
 JSR PC, PRIDIGT   ;print ten's place
 MOV R3, R2
 JSR PC, PRIDIGT   ;print one's place

 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R0
 RTS PC

;;;print 3digit number of R3 from adress (R0)
;;; param: R3 number which you want to print
;;;  R0 VRAM adress
NUMOUT3:MOV R0, -(SP)
 MOV R2, -(SP)
 MOV R3, -(SP)

 JSR PC, DIVHUND
 JSR PC, PRIDIGT   ;print hundred's place
 MOV R3, R2
 JSR PC, DIVTEN
 JSR PC, PRIDIGT   ;print ten's place
 MOV R3, R2
 JSR PC, PRIDIGT   ;print one's place

 MOV (SP)+, R3
 MOV (SP)+, R2
 MOV (SP)+, R0
 RTS PC


;;;print strings
;;; param: R0 VRAM adress
;;;  R1 top adress of strings
PRISTR: MOV R0, -(SP)
 MOV R1, -(SP)

 SUB #2., R0
1$: TST (R0)+
 MOVB (R1)+, (R0)
 BNE 1$

 MOV (SP)+, R1
 MOV (SP)+, R0
 RTS PC


;;;R0 = R0 + R5 * #VRAMLOOP
;;; param: R5 character ID number
;;; return: R0 VRAM adress
ADDVRAM:MOV R5, -(SP)

 CMP R5, #MAXTEAM0NUMBER
 BLE 1$
 SUB #16., R5

1$: TST (R5)+
2$: SUB #2., R5
 BLE 3$
 ADD #VRAMLOOP, R0
 BR 2$

3$: MOV (SP)+, R5
 RTS PC


;;;R0 = R0 + R5 * #VRAMLOOP
;;; param: R5 character ID number
;;; return: R0 graphic y position
ADDDRAW:MOV R5, -(SP)

 CMP R5, #MAXTEAM0NUMBER
 BLE 1$
 SUB #16., R5

1$: TST (R5)+
2$: SUB #2., R5
 BLE 3$
 ADD #15., R0
 BR 2$

3$: MOV (SP)+, R5

 RTS PC


;;;ABS(R2)
;;; param: R2
;;; return: R2
ABSR2: MOV R3, -(SP)

 MOV #177777, R3
 TST R2
 BGE 1$
 XOR R3, R2
 INC R2

1$: MOV (SP)+, R3
 RTS PC

 .END MAIN

コメント

このブログの人気の投稿

Eclipseでコードカバレッジのハイライトを削除する方法

Eclipseには便利なコードカバレッジ表示機能が搭載されていますが、コード内に緑、赤、黄の色付けがされて煩く感じるときもあると思います。 1度カバレッジの色付けが出てしまった後に消す方法の紹介です(方法は簡単)。 下記のキャプチャの青いマーカーで示した「Remove All Sessions」のボタンを押せばすべて消えます。

「特定の文字から始まらない文字列」にマッチする正規表現

「特定の文字から始まらない文字列」 にマッチする正規表現の例です。  以下の例では、Aから始まらない文字列にマッチする正規表現を示しています。 ^(?!A).*$ 私も正規表現の組み方で四苦八苦することがあります。以下の書籍は実践的に様々な正規表現のパターンを例示してくれているので、重宝しています。

ダイソーで買った200円のドライバーセットでHDDを分解

HDDの処分 最近は個人情報の問題もあって、HDDを処分する前にちゃんとデータの消去を気にすることも多くなってきました。消去方法としては大きく分けて下記の3つがあります。 データ消去ソフトでフォーマット HDD内部のプラッタを物理破壊 データ消去を行ってくれる専門の業者や家電量販店(Sofmapやビックカメラで実施していると思います。費用発生。)に持ち込み。 データ消去ソフトでのフォーマットは簡単ですが、欠点として「フォーマットに時間がかかる」「セクタ破損などで中途半端に壊れたディスクのフォーマットができない」などがあります。 またHDD内部のプラッタの物理破壊については、HDDを分解するために、通常のプラスやマイナスドライバーではなく、星形ネジに対応したトルクスドライバーが必要とのこともあって、少し面倒です。 筆者は今回、今後もHDDの廃棄をするだろうなあと思い、思い切って自分で分解して廃棄することにチャレンジしてみました。(家電量販店に持って行くよりも安くできないかというどケチ丸出しですw) HDDの星形ネジ こんなやつです。ちなみに写真はSeagateのST2000DL003というHDDで撮影しました。 トルクスドライバー というわけで、分解のために Amazonでトルクスドライバー を探しました。 調べると T8のもだと使えそう とのことで、いろいろと物色。 セットのものとか T8一本で立派なやつとか 色々あったのですが、HDD壊すだけで800円かぁ(←どケチ)、と思って購入を躊躇。 ネット上で調べると100円ショップのダイソーでも、トルクスドライバーを販売しているとの情報をキャッチ!近所のダイソーに行って、探したところ星形のヘッド交換に対応した精密ドライバーセットがありました。 プラスが10種類、マイナスが8種類、六角が6種類、星形が6種類(今回ほしかったもの)のセットで、何とお値段税抜き200円!、税抜き200円!と安かったので、ダメもとで購入しました。 結論から言うと 買って大正解 でした。 ダイソーの精密ドライバーセット こんな商品です! 星形対応のヘッドを装着するとこんな感じ。ドライバーのグリップもゴムで滑らない様になっていて使いやす...

SQLで特定の文字を組み合わせたランダムな文字列を生成

簡易的な方法として「指定した文字列からランダムに1文字選ぶ」を必要な文字の長さ分concat関数でつなげれば実現できます。 1文字ずつ文字を選ぶので、あまり性能もよくない上、セキュリティ的な観点からのランダム性も担保されていないので、あくまで開発中に必要になった時に使う程度が無難だと思います。 下記に英数字大文字小文字を含んだランダムな3文字の文字列を生成するクエリを示します。 # RAND関数で指定した文字列からランダムに1文字選択。 # 下記の例の62の部分はa~z、A~Z、1~9の文字数の合計値を入れた結果 SELECT CONCAT( SUBSTRING('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789', FLOOR(RAND() * 62 + 1), 1), SUBSTRING('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789', FLOOR(RAND() * 62 + 1), 1), SUBSTRING('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789', FLOOR(RAND() * 62 + 1), 1) ) AS random_string;

PHPの配列(array)のメモリ使用量の考察

はじめに 最近PHP上に大量のデータをメモリ上に展開していたのですが、配列(array)の形式(連想配列 or 単純な配列)や配列の要素のデータ構造(数字、配列、文字列など)で大きくメモリ使用量に差が出てくることに気づき、簡単なプログラムを組んで調べてみました。 あくまで筆者の環境での結果なので、細かい数値は参考程度に見てください。 測定環境と方法 OS: Windows 10 PHP 7.4.5 (php-7.4.5-nts-Win32-vc15-x64) 配列に要素を追加するプログラムを書いて、PHPのmemory_get_usage(true)関数を使って実メモリ使用量を計測しました。 計測結果 No. 方式 1MB当たり作成できる 要素数 プログラム 補足 1 キーも値も整数の配列 (整数IDを想定) 28571 // 2,000,000 / 70MB $row = []; for($i = 0; $i < 2000000; $i++) { $row[] = $i; } No.2~6でテストしたプログラム中の要素数は200,000。これだけ一桁多い! 2 キーが文字列、値が整数の連想配列 8333 // 200,000 / 24MB $row = []; for($i = 0; $i < 200000; $i++) { $row[$i.'_key_string'] = $i; } キーの文字列が長い方がメモリ使用量多くなる。 3 キーが整数、値が連想配列の配列 DBから取得してきたデータを想定 2325 // 200,000 / 86MB $row = []; for($i = 0; $i < 200000; $i++) { row[] = ['id' => $i]; } 4 キーが整数、値が連想配列の配列(配列に複数の値を保持) DBから取得してきたデータを想定 2127 // 200,000 /...

ADODB.streamオブジェクトを使って文字列とByte配列を相互変換(Excel VBA)

ADODB.streamオブジェクトを使って文字列をByte配列に変換するコードのサンプルです。 ExcelVBAでADODB.streamを使う際には、 1. ExcelのMicrosoft Visual Basic エディタのメニューバーから「ツール->参照設定」とたどる。 2. 表示されたダイアログからMicrosoft ActiveX Data Objectsにチェックを入れる。 という手順が必要です。 文字列からByte配列へ Private Function ADOS_EncodeStringToByte(ByVal cset As String, ByRef strUni As String) As Byte() On Error GoTo e Dim objStm As ADODB.stream: Set objStm = New ADODB.stream objStm.Mode = adModeReadWrite objStm.Open objStm.Type = adTypeText objStm.Charset = cset objStm.WriteText strUni objStm.Position = 0 objStm.Type = adTypeBinary Select Case UCase(cset) Case "UNICODE", "UTF-16" objStm.Position = 2 Case "UTF-8" objStm.Position = 3 End Select ADOS_EncodeStringToByte = objStm.Read() objStm.Close Set objStm = Nothing Exit Function e: Debug.Print "Error occurred while encoding characters" & Err.Description If objStm Is No...

Visual Studio 2010 SP1のアンインストール

Visual Studio 2013に乗り換えるためにVisual Studio 2010をアンインストールしようとしたところで問題発生。。。 先にVisual Studio 2010本体をアンインストールした後、Visual Studio 2010 SP1をアンインストールできなくて困っていました。 Google先生で調べたところ、以下の情報が見つかり、書かれていた通り実施したところ無事Visual Studio 2010 SP1のアンインストールに成功しました。 How to uninstall/remove Visual Studio SP1 アンインストール手順は以下の通りです。 http://www.microsoft.com/en-gb/download/details.aspx?id=23691 からMicrosoft Visual Studio 2010 Service Pack 1 (Installer)をダウンロード VS10sp1-KB983509.exeというファイル名でダウンロードされる(はず)。 コマンドプロンプトから以下のコマンドを実行 (以下の例は、c:\tempにVS10sp1-KB983509.exeがある場合) c:\temp\VS10sp1-KB983509.exe /uninstall /force ダイアログが立ち上がるので、アンインストールを選択して次へ進めばOK!

MySQL: SELECTの結果をUNIONして ORDER BYする際の最適化方法

SELECTの結果をUNIONして ORDER BY する際には下記の点に注意する必要があります。 無駄なメモリ消費 ソートにINDEXが利かない (≒CPU負荷増大) 対応策 可能であればPush-down Condition (各サブクエリ内でORDER BY, LIMIT, OFFSETを適用してからUNION, ORDER BYを実行する)を利用することで、 パフォーマンスを改善できる場合があります。 下記に例を示します。 もともとのクエリ SELECT tmp.* FROM ( SELECT tableA.column1, tableA.column2 FROM tableA WHERE (条件) UNION ALL SELECT tableB.column1, tableB.column2 FROM tableB WHERE (条件) ) AS tmp ORDER BY tmp.column1, tmp.column2 LIMIT 100, 20 Push-down Conditionを用いて書き直したクエリ SELECT tmp.* FROM ( SELECT tableA.column1, tableA.column2 FROM tableA WHERE (条件) ORDER BY tableA.column1, tableA.column2 LIMIT 30 # ただしこのPush-down Conditionの手法も下記の場合は、効果が半減しますので注意が必要です。 OFFSETの値が大きい場合は、結局全結果セットUNIONと変わらない サブクエリ内のソートで、INDEXが効かない場合

PHPでファイルを指定した行数ごとに分割

ファイルを指定した行数ごとに分割するためには、Linuxのsplitコマンドを使えば簡単に実現できます。 PHPではexec関数にsplitコマンドを渡して実行すればよいですが、下記の弱点があります。 Linuxのコマンドに依存 (PHPの場合はほとんどLinux環境で動作させることが普通なのでそこまで問題にならないかも知れません)。 exec関数は慎重に引数を渡さないと、OSコマンドインジェクション脆弱性を引き起こす可能性がある。 そこで、今回はPHPでファイルを指定した行数ごとに分割するプログラムを書いてみました。 <?php class FileSplitter { private $lines; private $fileCount; public function split($filePath, $linesPerFile, $outputDir) { $this->fileCount = 0; $this->lines = null; $file = new \SplFileObject($filePath); $lineCount = 0; try{ while (!$file->eof()) { if($lineCount % $linesPerFile === 0) { $this->writeToFile($this->generateOutputFilePath($outputDir, $file)); } $this->lines[] = $file->fgets(); $lineCount++; } $this->writeToFile($this->generateOutpu...

MySQLでGROUP_CONCATしたフィールドに対して疑似的にLIMITを実現する方法

MySQLでGROUP_CONCATしたフィールドに対して疑似的にLIMITを実現するには、GROUP_CONCATで生成された文字列に対して、SUBSTRING_INDEXを使って文字列を切り出す方法が簡単です。 # 下記はid, codeをカラムに持つテーブルで、codeカラムでGROUP BYして、codeごとにidをlimitで取得する例です。 SELECT code ,SUBSTRING_INDEX(GROUP_CONCAT(id ORDER BY id DESC), ',', :limit) # :limitの部分に取得したい件数を指定。 FROM table GROUP BY code 長所は、下記のように条件を指定して、LIMIT句で取得件数を指定したクエリを何度も発行する必要がないところです。 特に、一回あたりクエリの発行コストが高い場合は、GROUP_CONCATを使って一度に取得したほうが最終的な実行時間をかなり節約することができます。 SELECT id FROM table WHERE code = 'A' ORDER BY id DESC LIMIT :limit; ただし、短所も多いので、使用する際は、これらの短所について十分に考慮したうえで使ってください。 GROUP_CONCATで生成された文字列に対して、SUBSTRING_INDEXを使って文字列を切り出すという文字列処理なので、無駄が多い。 特にGROUP_CONCATで生成された元の文字列が長い場合。 GROUP_CONCATの区切り文字が、GROUP_CONCATされる元の文字列に含まれていると正しくLIMITされない。 例:GROUP_CONCATされる元の文字列にカンマが含まれているのに、カンマを区切り文字で指定している場合。 GROUP_CONCATの最大文字数制限を超えた場合は、機能しない。 MySQLのGROUP_CONCATの最大文字数制限は、「SHOW VARIABLES LIKE '%group_concat%';」で調べられます。デフォルト値は1024のようです。 ...