ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/DOSGame/trunk/MYGAME.ASM
Revision: 4
Committed: Wed Feb 11 15:26:06 2026 UTC (8 weeks, 4 days ago) by figdor32
File size: 5357 byte(s)
Log Message:
Initial check-in

File Contents

# User Rev Content
1 figdor32 4 ORG 100H
2     USE16
3    
4     include 'CONSTS.ASM'
5     include 'OBJTYPES.ASM'
6    
7     ; Unholy hack to reduce the amount of memory we get for the program because DOS is a big dum-dum and allocates the entire
8     ; free memory space, despite the fact that the program can only be up to 64K in size
9     MOV BX, 0x800 ; 32K (in paragraphs) NOTE: If this is not enough, the program will eventually crash when it gets bigger
10     ; Take great care to synchronize that with the .COM executable size!!!!!!!!!!!!!!
11     MOV AH, 4Ah ; MODIFY MEMORY BLOCK
12     INT 21h ; Me when Interrupt 21H (Disk Operating System Kernel Interrupt) [Real]
13     JC ERROR_GeneralDOSError ; Balls
14    
15     MOV DX, Filename
16     CALL DOS_OpenReadonly
17     JC ERROR_FileError ; Carry set means an error
18     ; If the branch was not taken, AX has the file handle.
19     ; We just store it in RAM for later since it's going to be useful for pretty much the entire runtime of the program
20     MOV [GameFileHandle], AX
21    
22     ; 1 Para = 16B
23    
24     MOV BX, 1024 ; 16K
25     CALL DOS_AllocateMemory ; Allocate scratch RAM
26     JC ERROR_GeneralDOSError
27     MOV [RAM_Scratch], AX
28    
29     MOV BX, 256 ; 4K again
30     CALL DOS_AllocateMemory ; Allocate persistent RAM
31     JC ERROR_GeneralDOSError
32     MOV [RAM_Persistent], AX
33    
34     MOV BX, 4096 ; Full 64K segment
35     CALL DOS_AllocateMemory ; Allocate object RAM
36     JC ERROR_GeneralDOSError
37     MOV [RAM_Object], AX
38    
39     MOV BX, 4096 ; Full 64K segment
40     CALL DOS_AllocateMemory ; Allocate the frame buffer
41     JC ERROR_GeneralDOSError
42     MOV [RAM_Framebuffer], AX
43    
44     MOV ES, [RAM_Scratch]
45    
46     ; Allocated segment in ES
47    
48     MOV BX, [GameFileHandle] ; File handle
49     MOV CX, 4 ; Number of bytes to read
50     MOV DX, 0 ; Offset into the buffer
51     CALL DOS_ReadFileIntoES ; Does the PUSH DS POP DS shenanigans
52     JC ERROR_GeneralDOSError ; If CF then error
53    
54     ; Does not mess with BX, and we still need BX for the handle.
55     CALL BASE_VerifyGameFileMagic
56    
57     MOV CX, 2
58     XOR DX, DX
59     CALL DOS_ReadFileIntoES ; Read a single byte indicating the version, and then one about how much memory to allocate, 0 is 16K, 1 is 32K, 2 is 64K
60     JC ERROR_GeneralDOSError
61    
62     ; Check the file version. Valid values are 1 and... well, just 1.
63     A_CheckVer:
64     MOV AL, [ES:0]
65     CMP AL, 1
66     JE .goodver
67     MOV DX, STR_ErrInvalidVersion
68     CALL DOS_PrintString
69     JMP Exit
70     .goodver:
71    
72     ; Read how much memory we want to allocate (0, 1, or 2 for 16, 32, and 64K respectively), allocate it, and store the segment
73     MOV AL, [ES:1]
74     CALL BASE_AllocFileMem
75     MOV [RAM_OpFile], AX
76    
77     MOV BX, [GameFileHandle] ; We probably lost BX long ago
78     MOV CX, 0xFFFF ; Read everything to end
79     MOV ES, [RAM_OpFile] ; Store the entire file in its alloc'd memory
80     XOR DX, DX ; Starting at offset 0 in ES:DX
81     CALL DOS_ReadFileIntoES
82     JC ERROR_GeneralDOSError
83    
84     MOV [FilePtr], 0 ; Reset the file pointer to 0, this is our "program counter"
85    
86     MOV CX, 3600 ; Object count, 3600 JUST fits, any more and we're out of memory
87     MOV ES, [RAM_Object]
88     CALL TABLE_InitializeBitmap
89    
90     CALL BIOS_SetVideoMode13H
91    
92     MOV DX, MyBmpFn
93     CALL BASE_AllocLoadFile ; ES:0 = Loaded file
94     MOV [BitmapSeg], ES
95    
96     MOV DX, MyBmpFn1
97     CALL BASE_AllocLoadFile ; ES:0 = Loaded file
98     MOV [BitmapSeg1], ES
99    
100    
101     MOV ES, [RAM_Object]
102    
103     MOV CX, 1
104     CALL TABLE_ObjAlloc
105    
106     ; AX Has obj h
107     CALL TABLE_ObjFree
108    
109     MOV CX, 1
110     CALL TABLE_ObjAlloc
111     PUSH AX
112     MOV CX, 1
113     CALL TABLE_ObjAlloc
114     CALL TABLE_GetObjectAddr
115     MOV WORD [ES:DI], 0xEFBE
116    
117     ;POP AX
118     ;MOV SI, TestStr
119     ;CALL OBJ_STRING_FillString
120    
121     ;JMP $
122    
123     ;TestStr db 'According to all known laws of aviation, there is no way a bee should be able to fly.', 0
124    
125     ;JMP $
126    
127     NewTestDrwLoop:
128     MOV AL, 0x01 ; Blue
129     CALL BASE_ClearScreen
130    
131     MOV ES, [BitmapSeg]
132     XOR SI, SI
133     MOV CX, [XPos] ; X
134     MOV DX, [YPos] ; Y
135     CALL BASE_DrawBitmapFromFile
136     ADD [XPos], 1
137    
138     ;MOV ES, [BitmapSeg1]
139     ;XOR SI, SI
140     ;MOV CX, [XPos1] ; X
141     ;MOV DX, [YPos1] ; Y
142     ;CALL BASE_DrawBitmapFromFile
143     ;SUB [XPos1], 1
144    
145     CALL BASE_Present
146     JMP NewTestDrwLoop
147    
148     BitmapSeg dw ?
149     BitmapSeg1 dw ?
150     MyBmpFn db 'WIDE.BMA', 0x00
151     MyBmpFn1 db 'BMPMOON.BMA', 0x00
152     XPos dw 0
153     YPos dw 0
154     XPos1 dw 0
155     YPos1 dw 0
156    
157     JMP $
158     CALL BIOS_SetVideoMode03H ; If Exit is called, the mode is likely already 03H, and we don't want to clear the framebuffer, which this does
159     Exit:
160    
161     MOV BX, [GameFileHandle]
162     CALL DOS_CloseFile
163     JC FileCloseError
164    
165     ; Free all memory blocks
166     ; We use CX to see whether the carry has been set within one or more calls, since we want to continue even if there was an error
167     ; So we just use ADC CX, 0 to add the carry to CX, if CF = 0, CX = 0
168     CLC
169     XOR CX, CX
170    
171     MOV ES, [RAM_Scratch]
172     CALL DOS_FreeMemory
173     ADC CX, 0
174    
175     MOV ES, [RAM_Persistent]
176     CALL DOS_FreeMemory
177     ADC CX, 0
178    
179     MOV ES, [RAM_Object]
180     CALL DOS_FreeMemory
181     ADC CX, 0
182    
183     MOV ES, [RAM_OpFile]
184     CALL DOS_FreeMemory
185     ADC CX, 0
186    
187     CMP CX, 0
188     JE .noerror
189    
190     MOV DX, STR_ErrFree
191     CALL DOS_PrintString
192     .noerror:
193    
194     MOV DX, STR_Bye
195     CALL DOS_PrintString
196    
197     ; CALL BIOS_SetVideoMode03H ; Fix the video mode
198     INT 20H ; ENDOF Program
199    
200     include 'ERRORS.ASM'
201     include 'DOSFUNC.ASM'
202     include 'BIOSFUNC.ASM'
203     include 'BASEFUNC.ASM'
204     include 'HEAPUTIL.ASM'
205     include 'OBJUTILS.ASM'
206     include 'STATVAR.ASM'