Raw File
1 ; _____________________________________________
2 ; | |
3 ; | Project: APPLER |
4 ; | File: DRAM.INC |
5 ; | Compiler: 16-bit TASM (2.5) |
6 ; | |
7 ; | Subject: RAM Card Emulation |
8 ; | |
9 ; | Author: Alexander Patalenski |
10 ; |_____________________________________________|
11
12 ; This file is included in EMULATE.ASM
13
14 ;-------------- DRAM emulation entries -----------------------------------------
15
16 assume CS:Emulate,DS:Apple,ES:Video,SS:Data
17
18 UseNextFreeSpace
19
20 ResetDRAM proc far
21 mov ax,Apple
22 mov ds,ax
23 mov ax,Video
24 mov es,ax
25 mov al,82h
26 mov di,offset ResetDRAM_1
27 jmp C08Xr
28 ResetDRAM_1: mov al,82h
29 mov di,offset ResetDRAM_2
30 jmp C08Xr
31 ResetDRAM_2: ret
32 ResetDRAM endp
33
34 ; Entry:
35 ; bx - file handle
36 ; Action:
37 ; load memory banks
38 ; Exit:
39 ; CF: 0-ok, 1-error (don't close file)
40 DRAMLoad proc far
41 push ax cx dx ds
42 mov ax,seg Bank1
43 mov ds,ax
44 mov dx,offset Bank1
45 mov cx,4000h
46 mov ah,3Fh
47 int 21h
48 cmp ax,cx
49 pop ds dx cx ax
50 ret
51 DRAMLoad endp
52
53 ; Entry:
54 ; bx - file handle
55 ; Action:
56 ; save memory banks
57 ; Exit:
58 ; CF: 0-ok, 1-error (don't close file)
59 DRAMSave proc far
60 push ax cx dx ds
61 mov ax,seg Bank1
62 mov ds,ax
63 mov dx,offset Bank1
64 mov cx,4000h
65 mov ah,40h
66 int 21h
67 cmp ax,cx
68 pop ds dx cx ax
69 ret
70 DRAMSave endp
71 CheckAddress
72
73 UseNextFreeSpace
74 C08Xr: and al,0Fh
75 mov bx,offset C080readTbl
76 xlat CS:[bx]
77 mov bh,C080
78 mov bl,bh
79 shl bl,1
80 or bl,bh
81 or bl,00000111b
82 and bl,al
83 mov al,bl
84 mov C080,al
85 xor al,bh
86 test al,1011b
87 jnz C08Xr_10
88 mov bl,ch
89 jmp di
90
91 C08Xr_10: push cs
92 push di ; BH/BL - old/new C080 value
93 jmp SetDRAM ; AL - BH xor BL
94
95 C080readTbl db 0010b,1100b,0000b,1110b,0010b,1100b,0000b,1110b
96 db 0011b,1101b,0001b,1111b,0011b,1101b,0001b,1111b
97 CheckAddress
98
99 UseNextFreeSpace
100 C08Xw: and al,0Fh
101 mov bx,offset C080writeTbl
102 xlat CS:[bx]
103 mov bh,C080
104 mov bl,bh
105 or bl,00000111b
106 and bl,al
107 mov al,bl
108 mov C080,al
109 xor al,bh
110 test al,1011b
111 jz C08Xw_10
112 Save ax
113 call SetDRAM ; BH/BL - old/new C080 value
114 Restore ax ; AL - BH xor BL
115 C08Xw_10: sahf
116 mov bl,ch
117 DoNext
118
119 C080writeTbl db 0010b,1000b,0000b,1010b,0010b,1000b,0000b,1010b
120 db 0011b,1001b,0001b,1011b,0011b,1001b,0001b,1011b
121 CheckAddress
122
123 ;-------------- DRAM emulation subroutines -------------------------------------
124
125 Peripher segment public
126 assume CS:Peripher,DS:Nothing,ES:Nothing
127
128 SetDRAM Proc far
129 ; BH/BL - old/new C080 value, AL - BH xor BL
130
131 test al,0011b
132 jz SetDRAM_20
133
134 Save bx cx dx si bp ds es
135 test al,0001b
136 jz SetDRAM_10
137 Save ax
138 test bh,0010b ; Swap Bank1<->Bank2
139 mov ax,offset Bank1
140 mov bx,offset Bank2
141 mov bp,seg Bank2
142 mov ds,bp
143 jz SetDRAM_05
144 mov bx,0D000h
145 mov bp,Apple
146 SetDRAM_05: mov dx,1000h/1000h
147 call SwapMem
148 Restore ax
149 test al,0010b
150 jz SetDRAM_15
151
152 SetDRAM_10: mov ax,seg DRAM ; Swap ROM<->RAM
153 mov ds,ax
154 mov ax,offset DRAM
155 mov bx,0D000h
156 mov bp,Apple
157 mov dx,3000h/1000h
158 call SwapMem
159 SetDRAM_15: Restore bx cx dx si bp ds es
160
161 SetDRAM_20: test bl,1000b ; Set write mode :
162 mov ax,DRAM_DoNotWrite ; 1 - read/write
163 jz SetDRAM_25 ; 2 - write only
164 test bl,0010b ; 3 - don't write
165 mov ax,DRAM_WriteOnly
166 jz SetDRAM_25
167 mov ax,DRAM_ReadWrite
168
169 SetDRAM_25: mov bx,ds
170 mov di,Emulate
171 mov ds,di
172 Temp = 0
173 REPT 100h-0D0h
174 mov DS:DRAM_ModefyAdr[Temp],ax
175 Temp = Temp+100h
176 ENDM
177 mov ds,bx
178 mov bl,ch
179 ret
180 SetDRAM Endp
181
182
183 SwapMem Proc near
184 cld
185 SwapMem_10: mov si,ax
186 mov di,offset Buffer1000h
187 mov cx,seg Buffer1000h
188 mov es,cx
189 mov cx,1000h/2
190 rep movsw
191 mov di,ax
192 mov ax,si
193 mov si,bx
194 mov cx,ds
195 mov es,cx
196 mov ds,bp
197 mov cx,1000h/2
198 rep movsw
199 mov di,bx
200 mov bx,si
201 mov si,offset Buffer1000h
202 mov bp,es
203 mov cx,ds
204 mov es,cx
205 mov cx,seg Buffer1000h
206 mov ds,cx
207 mov cx,1000h/2
208 rep movsw
209 mov ds,bp
210 mov bp,es
211 dec dx
212 jnz SwapMem_10
213 ret
214 SwapMem Endp
215
216 Data segment stack 'stack'
217 even
218 Bank1 db 1000h dup(0)
219 Bank2 Label byte
220 DRAM db 3000h dup(0)
221 Data ends
222
223 Peripher ends
224
Generated by GNU Enscript 1.6.6, and GophHub 1.3.