]> 4ch.mooo.com Git - 16.git/blob - src/lib/exmm/MEMORY.ASM
We actually have a working EMS library now~ yay! I am going to experiment and play...
[16.git] / src / lib / exmm / MEMORY.ASM
1 .387\r
2                 PUBLIC  _OpenEMM\r
3                 PUBLIC  _CloseEMM\r
4                 PUBLIC  _EMMInstalled\r
5                 PUBLIC  _EMMCoreLeft\r
6                 PUBLIC  _EMMalloc\r
7                 PUBLIC  _EMMRealloc\r
8                 PUBLIC  _EMMFree\r
9                 PUBLIC  _MapEMM\r
10                 PUBLIC  _UnmapEMM\r
11                 PUBLIC  _UseEMM\r
12                 PUBLIC  _SaveEMM\r
13                 EXTRN   `F_LXLSH@`:BYTE\r
14                 EXTRN   `F_SCOPY@`:BYTE\r
15 MEMORY_TEXT             SEGMENT BYTE PUBLIC USE16 'CODE'\r
16                 ASSUME CS:MEMORY_TEXT, DS:DGROUP, SS:DGROUP\r
17 _OpenEMM:\r
18     push        bp \r
19     mov         bp,sp \r
20     push        ds \r
21     mov         ax,MEMORY_DATA \r
22     mov         ds,ax \r
23     call        far ptr L$65 \r
24     or          ax,ax \r
25     je          L$1 \r
26     call        far ptr L$72 \r
27     or          ax,ax \r
28     jne         L$3 \r
29 L$1:\r
30     xor         ax,ax \r
31 L$2:\r
32     jmp         L$5 \r
33 L$3:\r
34     call        far ptr L$76 \r
35     mov         word ptr L$99,ax \r
36     or          ax,ax \r
37     jne         L$4 \r
38     jmp         L$1 \r
39 L$4:\r
40     mov         ax,1 \r
41     jmp         L$2 \r
42 L$5:\r
43     pop         ds \r
44     pop         bp \r
45     retf        \r
46 _CloseEMM:\r
47     push        bp \r
48     mov         bp,sp \r
49     push        si \r
50     push        ds \r
51     mov         ax,MEMORY_DATA \r
52     mov         ds,ax \r
53     cmp         word ptr L$99,0 \r
54     jne         L$6 \r
55     jmp         L$10 \r
56 L$6:\r
57     xor         si,si \r
58     jmp         L$9 \r
59 L$7:\r
60     mov         bx,si \r
61     shl         bx,1 \r
62     cmp         word ptr L$100[bx],0 \r
63     je          L$8 \r
64     mov         bx,si \r
65     shl         bx,1 \r
66     push        word ptr L$100[bx] \r
67     call        far ptr L$87 \r
68     pop         cx \r
69     mov         bx,si \r
70     shl         bx,1 \r
71     mov         word ptr L$100[bx],0 \r
72 L$8:\r
73     inc         si \r
74 L$9:\r
75     cmp         si,40H \r
76     jl          L$7 \r
77     mov         word ptr L$99,0 \r
78 L$10:\r
79     pop         ds \r
80     pop         si \r
81     pop         bp \r
82     retf        \r
83 _EMMInstalled:\r
84     push        bp \r
85     mov         bp,sp \r
86     push        ds \r
87     mov         ax,MEMORY_DATA \r
88     mov         ds,ax \r
89     cmp         word ptr L$99,0 \r
90     je          L$11 \r
91     mov         ax,1 \r
92     jmp         L$12 \r
93 L$11:\r
94     xor         ax,ax \r
95 L$12:\r
96     jmp         L$13 \r
97 L$13:\r
98     pop         ds \r
99     pop         bp \r
100     retf        \r
101 _EMMCoreLeft:\r
102     push        bp \r
103     mov         bp,sp \r
104     sub         sp,6 \r
105     push        ds \r
106     mov         ax,MEMORY_DATA \r
107     mov         ds,ax \r
108     mov         word ptr -4[bp],0 \r
109     mov         word ptr -6[bp],0 \r
110     mov         ah,42H \r
111     int         67H \r
112     or          ah,ah \r
113     js          L$14 \r
114     mov         word ptr -2[bp],bx \r
115     mov         ax,word ptr -2[bp] \r
116     xor         dx,dx \r
117     mov         cl,0eH \r
118     call        far ptr `F_LXLSH@` \r
119     mov         word ptr -4[bp],dx \r
120     mov         word ptr -6[bp],ax \r
121 L$14:\r
122     mov         dx,word ptr -4[bp] \r
123     mov         ax,word ptr -6[bp] \r
124     jmp         L$15 \r
125 L$15:\r
126     pop         ds \r
127     mov         sp,bp \r
128     pop         bp \r
129     retf        \r
130 _EMMalloc:\r
131     push        bp \r
132     mov         bp,sp \r
133     sub         sp,4 \r
134     push        si \r
135     push        di \r
136     push        ds \r
137     mov         ax,MEMORY_DATA \r
138     mov         ds,ax \r
139     mov         di,word ptr 0aH[bp] \r
140     mov         word ptr -2[bp],0 \r
141     mov         word ptr -4[bp],0 \r
142     cmp         word ptr L$99,0 \r
143     jne         L$18 \r
144     les         bx,dword ptr 6[bp] \r
145     mov         word ptr es:[bx],0 \r
146 L$16:\r
147     xor         dx,dx \r
148     xor         ax,ax \r
149 L$17:\r
150     jmp         L$26 \r
151 L$18:\r
152     cmp         di,1 \r
153     jl          L$19 \r
154     cmp         di,3fcH \r
155     jle         L$20 \r
156 L$19:\r
157     les         bx,dword ptr 6[bp] \r
158     mov         word ptr es:[bx],0f440H \r
159     jmp         L$16 \r
160 L$20:\r
161     xor         si,si \r
162     jmp         L$22 \r
163 L$21:\r
164     inc         si \r
165 L$22:\r
166     cmp         si,40H \r
167     jge         L$23 \r
168     mov         bx,si \r
169     shl         bx,1 \r
170     cmp         word ptr L$100[bx],0 \r
171     jne         L$21 \r
172 L$23:\r
173     cmp         si,40H \r
174     jne         L$24 \r
175     les         bx,dword ptr 6[bp] \r
176     mov         word ptr es:[bx],0f443H \r
177     jmp         L$16 \r
178 L$24:\r
179     push        di \r
180     call        far ptr L$80 \r
181     pop         cx \r
182     mov         bx,si \r
183     shl         bx,1 \r
184     mov         word ptr L$100[bx],ax \r
185     or          ax,ax \r
186     jle         L$25 \r
187     mov         ax,word ptr L$99 \r
188     mov         word ptr -2[bp],ax \r
189     mov         word ptr -4[bp],0 \r
190 L$25:\r
191     mov         bx,si \r
192     shl         bx,1 \r
193     mov         ax,word ptr L$100[bx] \r
194     les         bx,dword ptr 6[bp] \r
195     mov         word ptr es:[bx],ax \r
196     mov         dx,word ptr -2[bp] \r
197     mov         ax,word ptr -4[bp] \r
198     jmp         L$17 \r
199 L$26:\r
200     pop         ds \r
201     pop         di \r
202     pop         si \r
203     mov         sp,bp \r
204     pop         bp \r
205     retf        \r
206 _EMMRealloc:\r
207     push        bp \r
208     mov         bp,sp \r
209     push        ds \r
210     mov         ax,MEMORY_DATA \r
211     mov         ds,ax \r
212     xor         cx,cx \r
213     cmp         word ptr L$99,0 \r
214     je          L$27 \r
215     cmp         word ptr 8[bp],0 \r
216     jl          L$27 \r
217     cmp         word ptr 8[bp],3fcH \r
218     jle         L$29 \r
219 L$27:\r
220     xor         ax,ax \r
221 L$28:\r
222     jmp         L$31 \r
223 L$29:\r
224     mov         ah,51H \r
225     mov         bx,word ptr 8[bp] \r
226     mov         dx,word ptr 6[bp] \r
227     int         67H \r
228     or          ah,ah \r
229     js          L$30 \r
230     mov         cx,1 \r
231 L$30:\r
232     mov         ax,cx \r
233     jmp         L$28 \r
234 L$31:\r
235     pop         ds \r
236     pop         bp \r
237     retf        \r
238 _EMMFree:\r
239     push        bp \r
240     mov         bp,sp \r
241     push        si \r
242     push        di \r
243     push        ds \r
244     mov         ax,MEMORY_DATA \r
245     mov         ds,ax \r
246     cmp         word ptr L$99,0 \r
247     jne         L$32 \r
248     jmp         L$40 \r
249 L$32:\r
250     xor         si,si \r
251     jmp         L$34 \r
252 L$33:\r
253     inc         si \r
254 L$34:\r
255     cmp         si,40H \r
256     jge         L$35 \r
257     mov         bx,si \r
258     shl         bx,1 \r
259     mov         ax,word ptr L$100[bx] \r
260     cmp         ax,word ptr 6[bp] \r
261     jne         L$33 \r
262 L$35:\r
263     cmp         si,40H \r
264     jl          L$36 \r
265     jmp         L$40 \r
266 L$36:\r
267     mov         di,10H \r
268     jmp         L$38 \r
269 L$37:\r
270     mov         bx,si \r
271     shl         bx,1 \r
272     push        word ptr L$100[bx] \r
273     call        far ptr L$87 \r
274     pop         cx \r
275     or          ax,ax \r
276     je          L$38 \r
277     jmp         L$39 \r
278 L$38:\r
279     mov         ax,di \r
280     dec         di \r
281     or          ax,ax \r
282     jne         L$37 \r
283 L$39:\r
284     mov         bx,si \r
285     shl         bx,1 \r
286     mov         word ptr L$100[bx],0 \r
287 L$40:\r
288     pop         ds \r
289     pop         di \r
290     pop         si \r
291     pop         bp \r
292     retf        \r
293 _MapEMM:\r
294     push        bp \r
295     mov         bp,sp \r
296     push        si \r
297     push        di \r
298     push        ds \r
299     mov         ax,MEMORY_DATA \r
300     mov         ds,ax \r
301     mov         di,word ptr 0aH[bp] \r
302     cmp         word ptr L$99,0 \r
303     jne         L$43 \r
304 L$41:\r
305     xor         ax,ax \r
306 L$42:\r
307     jmp         L$53 \r
308 L$43:\r
309     xor         si,si \r
310     jmp         L$45 \r
311 L$44:\r
312     inc         si \r
313 L$45:\r
314     cmp         si,40H \r
315     jge         L$46 \r
316     mov         bx,si \r
317     shl         bx,1 \r
318     mov         ax,word ptr L$100[bx] \r
319     cmp         ax,word ptr 6[bp] \r
320     jne         L$44 \r
321 L$46:\r
322     cmp         si,40H \r
323     jne         L$47 \r
324     jmp         L$41 \r
325 L$47:\r
326     push        word ptr 6[bp] \r
327     call        far ptr L$91 \r
328     pop         cx \r
329     cmp         ax,di \r
330     jl          L$48 \r
331     cmp         di,1 \r
332     jl          L$48 \r
333     cmp         di,4 \r
334     jle         L$49 \r
335 L$48:\r
336     mov         ax,0f440H \r
337     jmp         L$42 \r
338 L$49:\r
339     mov         si,word ptr 8[bp] \r
340     jmp         L$52 \r
341 L$50:\r
342     mov         ax,si \r
343     sub         ax,word ptr 8[bp] \r
344     push        ax \r
345     push        si \r
346     push        word ptr 6[bp] \r
347     call        far ptr L$84 \r
348     add         sp,6 \r
349     or          ax,ax \r
350     jne         L$51 \r
351     jmp         L$41 \r
352 L$51:\r
353     inc         si \r
354 L$52:\r
355     mov         ax,word ptr 8[bp] \r
356     add         ax,di \r
357     cmp         ax,si \r
358     jg          L$50 \r
359     mov         ax,1 \r
360     jmp         L$42 \r
361 L$53:\r
362     pop         ds \r
363     pop         di \r
364     pop         si \r
365     pop         bp \r
366     retf        \r
367 _UnmapEMM:\r
368     push        bp \r
369     mov         bp,sp \r
370     sub         sp,2 \r
371     push        si \r
372     push        di \r
373     push        ds \r
374     mov         ax,MEMORY_DATA \r
375     mov         ds,ax \r
376     mov         di,word ptr 6[bp] \r
377     cmp         word ptr L$99,0 \r
378     jne         L$54 \r
379     jmp         L$63 \r
380 L$54:\r
381     xor         si,si \r
382     jmp         L$56 \r
383 L$55:\r
384     inc         si \r
385 L$56:\r
386     cmp         si,40H \r
387     jge         L$57 \r
388     mov         bx,si \r
389     shl         bx,1 \r
390     cmp         word ptr L$100[bx],di \r
391     jne         L$55 \r
392 L$57:\r
393     cmp         si,40H \r
394     jne         L$58 \r
395     jmp         L$63 \r
396 L$58:\r
397     mov         ax,word ptr 8[bp] \r
398     add         ax,word ptr 0aH[bp] \r
399     mov         word ptr -2[bp],ax \r
400     cmp         word ptr 0aH[bp],1 \r
401     jl          L$59 \r
402     cmp         word ptr -2[bp],4 \r
403     jle         L$60 \r
404 L$59:\r
405     jmp         L$63 \r
406 L$60:\r
407     mov         si,word ptr 8[bp] \r
408     jmp         L$62 \r
409 L$61:\r
410     push        si \r
411     mov         ax,0ffffH \r
412     push        ax \r
413     push        di \r
414     call        far ptr L$84 \r
415     add         sp,6 \r
416     inc         si \r
417 L$62:\r
418     cmp         si,word ptr -2[bp] \r
419     jl          L$61 \r
420 L$63:\r
421     pop         ds \r
422     pop         di \r
423     pop         si \r
424     mov         sp,bp \r
425     pop         bp \r
426     retf        \r
427 _UseEMM:\r
428     push        bp \r
429     mov         bp,sp \r
430     push        si \r
431     push        ds \r
432     mov         ax,MEMORY_DATA \r
433     mov         ds,ax \r
434     mov         si,word ptr 6[bp] \r
435     push        si \r
436     call        far ptr L$94 \r
437     pop         cx \r
438     push        word ptr 0aH[bp] \r
439     push        word ptr 8[bp] \r
440     push        si \r
441     push        cs \r
442     call        near ptr _MapEMM \r
443     add         sp,6 \r
444     jmp         L$64 \r
445 L$64:\r
446     pop         ds \r
447     pop         si \r
448     pop         bp \r
449     retf        \r
450 _SaveEMM:\r
451     push        bp \r
452     mov         bp,sp \r
453     push        si \r
454     push        ds \r
455     mov         ax,MEMORY_DATA \r
456     mov         ds,ax \r
457     mov         si,word ptr 6[bp] \r
458     push        word ptr 0aH[bp] \r
459     push        word ptr 8[bp] \r
460     push        si \r
461     push        cs \r
462     call        near ptr _UnmapEMM \r
463     add         sp,6 \r
464     push        si \r
465     call        far ptr L$97 \r
466     pop         cx \r
467     pop         ds \r
468     pop         si \r
469     pop         bp \r
470     retf        \r
471 L$65:\r
472     push        bp \r
473     mov         bp,sp \r
474     sub         sp,14H \r
475     push        ds \r
476     mov         ax,MEMORY_DATA \r
477     mov         ds,ax \r
478     lea         ax,-0cH[bp] \r
479     push        ss \r
480     push        ax \r
481     mov         ax,offset L$98 \r
482     push        ds \r
483     push        ax \r
484     mov         cx,9 \r
485     call        far ptr `F_SCOPY@` \r
486     push        es \r
487     mov         ax,3567H \r
488     int         21H \r
489     mov         ax,es \r
490     mov         word ptr -2[bp],ax \r
491     pop         es \r
492     mov         ax,word ptr -2[bp] \r
493     mov         word ptr -12H[bp],ax \r
494     mov         word ptr -14H[bp],0aH \r
495     lea         ax,-0cH[bp] \r
496     mov         word ptr -0eH[bp],ss \r
497     mov         word ptr -10H[bp],ax \r
498     xor         dx,dx \r
499     jmp         L$67 \r
500 L$66:\r
501     inc         dx \r
502 L$67:\r
503     cmp         dx,8 \r
504     jge         L$68 \r
505     les         bx,dword ptr -10H[bp] \r
506     inc         word ptr -10H[bp] \r
507     mov         al,byte ptr es:[bx] \r
508     les         bx,dword ptr -14H[bp] \r
509     inc         word ptr -14H[bp] \r
510     cmp         al,byte ptr es:[bx] \r
511     je          L$66 \r
512 L$68:\r
513     cmp         dx,8 \r
514     jne         L$70 \r
515     mov         ax,1 \r
516 L$69:\r
517     jmp         L$71 \r
518 L$70:\r
519     xor         ax,ax \r
520     jmp         L$69 \r
521 L$71:\r
522     pop         ds \r
523     mov         sp,bp \r
524     pop         bp \r
525     retf        \r
526 L$72:\r
527     push        bp \r
528     mov         bp,sp \r
529     push        ds \r
530     mov         ax,MEMORY_DATA \r
531     mov         ds,ax \r
532     mov         ah,40H \r
533     int         67H \r
534     or          ah,ah \r
535     jns         L$74 \r
536     xor         ax,ax \r
537 L$73:\r
538     jmp         L$75 \r
539 L$74:\r
540     mov         ax,1 \r
541     jmp         L$73 \r
542 L$75:\r
543     pop         ds \r
544     pop         bp \r
545     retf        \r
546 L$76:\r
547     push        bp \r
548     mov         bp,sp \r
549     sub         sp,2 \r
550     push        ds \r
551     mov         ax,MEMORY_DATA \r
552     mov         ds,ax \r
553     mov         ah,41H \r
554     int         67H \r
555     or          ah,ah \r
556     js          L$78 \r
557     mov         word ptr -2[bp],bx \r
558     mov         ax,word ptr -2[bp] \r
559 L$77:\r
560     jmp         L$79 \r
561 L$78:\r
562     xor         ax,ax \r
563     jmp         L$77 \r
564 L$79:\r
565     pop         ds \r
566     mov         sp,bp \r
567     pop         bp \r
568     retf        \r
569 L$80:\r
570     push        bp \r
571     mov         bp,sp \r
572     sub         sp,2 \r
573     push        ds \r
574     mov         ax,MEMORY_DATA \r
575     mov         ds,ax \r
576     mov         ah,43H \r
577     mov         bx,word ptr 6[bp] \r
578     int         67H \r
579     or          ah,ah \r
580     js          L$82 \r
581     mov         word ptr -2[bp],dx \r
582     mov         ax,word ptr -2[bp] \r
583 L$81:\r
584     jmp         L$83 \r
585 L$82:\r
586     xor         ax,ax \r
587     jmp         L$81 \r
588 L$83:\r
589     pop         ds \r
590     mov         sp,bp \r
591     pop         bp \r
592     retf        \r
593 L$84:\r
594     push        bp \r
595     mov         bp,sp \r
596     push        ds \r
597     mov         ax,MEMORY_DATA \r
598     mov         ds,ax \r
599     xor         cx,cx \r
600     mov         ax,word ptr 0aH[bp] \r
601     mov         ah,44H \r
602     mov         bx,word ptr 8[bp] \r
603     mov         dx,word ptr 6[bp] \r
604     int         67H \r
605     or          ah,ah \r
606     js          L$85 \r
607     mov         cx,1 \r
608 L$85:\r
609     mov         ax,cx \r
610     jmp         L$86 \r
611 L$86:\r
612     pop         ds \r
613     pop         bp \r
614     retf        \r
615 L$87:\r
616     push        bp \r
617     mov         bp,sp \r
618     push        ds \r
619     mov         ax,MEMORY_DATA \r
620     mov         ds,ax \r
621     mov         ah,45H \r
622     mov         dx,word ptr 6[bp] \r
623     int         67H \r
624     or          ah,ah \r
625     js          L$89 \r
626     mov         ax,1 \r
627 L$88:\r
628     jmp         L$90 \r
629 L$89:\r
630     xor         ax,ax \r
631     jmp         L$88 \r
632 L$90:\r
633     pop         ds \r
634     pop         bp \r
635     retf        \r
636 L$91:\r
637     push        bp \r
638     mov         bp,sp \r
639     sub         sp,2 \r
640     push        ds \r
641     mov         ax,MEMORY_DATA \r
642     mov         ds,ax \r
643     mov         word ptr -2[bp],0 \r
644     mov         ah,4cH \r
645     mov         dx,word ptr 6[bp] \r
646     int         67H \r
647     or          ah,ah \r
648     js          L$92 \r
649     mov         word ptr -2[bp],bx \r
650 L$92:\r
651     mov         ax,word ptr -2[bp] \r
652     jmp         L$93 \r
653 L$93:\r
654     pop         ds \r
655     mov         sp,bp \r
656     pop         bp \r
657     retf        \r
658 L$94:\r
659     push        bp \r
660     mov         bp,sp \r
661     push        ds \r
662     mov         ax,MEMORY_DATA \r
663     mov         ds,ax \r
664     mov         bx,0f442H \r
665     mov         ah,47H \r
666     mov         dx,word ptr 6[bp] \r
667     int         67H \r
668     or          ah,ah \r
669     js          L$95 \r
670     mov         bx,1 \r
671 L$95:\r
672     mov         ax,bx \r
673     jmp         L$96 \r
674 L$96:\r
675     pop         ds \r
676     pop         bp \r
677     retf        \r
678 L$97:\r
679     push        bp \r
680     mov         bp,sp \r
681     push        ds \r
682     mov         ax,MEMORY_DATA \r
683     mov         ds,ax \r
684     mov         ah,48H \r
685     mov         dx,word ptr 6[bp] \r
686     int         67H \r
687     pop         ds \r
688     pop         bp \r
689     retf        \r
690 MEMORY_TEXT             ENDS\r
691 MEMORY_DATA             SEGMENT WORD PUBLIC USE16 'FAR_DATA'\r
692 L$98:\r
693     DB  45H, 4dH, 4dH, 58H, 58H, 58H, 58H, 30H\r
694     DB  0\r
695 L$99:\r
696     DB  0, 0\r
697 L$100:\r
698     DB  0FH DUP(0,0,0,0,0,0,0,0)\r
699     DB  0, 0, 0, 0, 0, 0, 0, 0\r
700 \r
701 MEMORY_DATA             ENDS\r
702                 END\r