--- np2/i286x/memory.x86 2003/12/08 00:55:31 1.4 +++ np2/i286x/memory.x86 2005/02/08 09:18:59 1.13 @@ -6,17 +6,17 @@ section .bss - extern _mem + global _mem extern _i286core extern _grcg - extern _extmem extern _gdcs extern _tramupdate extern _vramupdate extern _cgwindow -; extern ___font extern _vramop +_mem resb 0x200000 + MAINMEMORY equ _mem EXTMEMORY equ 0 @@ -76,22 +76,21 @@ extern @tracevramwrite_w@8 %endmacro %endif - section .text ; ----------------------------------------------------------------- write byte %if USE_EGCASM - extern _egca_read - extern _egca_read_w - extern _egca_write - extern _egca_write_w + extern egc_read + extern egc_read_w + extern egc_write + extern egc_write_w %else - extern @egc_read@4 - extern @egc_read_w@4 - extern @egc_write@8 - extern @egc_write_w@8 + extern @memegc_rd8@4 + extern @memegc_rd16@4 + extern @memegc_wr8@8 + extern @memegc_wr16@8 %endif ; normal memory @@ -121,6 +120,8 @@ wtram_a: cmp ecx, 000a3fe0h jc short wtram_m cmp ecx, 000a4000h jnc wcgwindow_s + test ecx, 2 + je short wtram_m cmp byte [_gdcs + gdcs_t.msw_accessable], 0 je short wtram_e wtram_m: shr ebx, 1 @@ -261,12 +262,14 @@ grcgtdw_end: pop ecx ; EGC bridge align 16 @egc_wt: VRAMTRACE + mov ebx, [_vramop + vramop_t.grcgwait] + sub [_i286core + i286core_t.remainclock], ebx pop ebx %if USE_EGCASM - jmp _egca_write ; ver0.26 + jmp egc_write %else pushad - call @egc_write@8 + call @memegc_wr8@8 popad ret %endif @@ -278,12 +281,16 @@ grcgtdw_end: pop ecx and ecx, 3fffh shr ebx, 12 and ebx, byte (3*4) - add ecx, [_extmem + extmem_t.pageptr + ebx] - mov [EXTMEMORY + ecx], dl ; ver0.28 + add ecx, [_i286core + i286core_t.ems + ebx] + mov [EXTMEMORY + ecx], dl pop ecx pop ebx ret +@i286_wb: mov [MAINMEMORY + 1c8000h - 0e8000h + ecx], dl + pop ebx + ret + ; non writable memory align 16 @i286_wn: pop ebx @@ -378,12 +385,14 @@ grcgtcr_end: not al ; EGC bridge align 16 -@egc_rd: pop ebx +@egc_rd: mov ebx, [_vramop + vramop_t.grcgwait] + sub [_i286core + i286core_t.remainclock], ebx + pop ebx %if USE_EGCASM - jmp _egca_read ; ver0.26 + jmp egc_read %else pushad - call @egc_read@4 + call @memegc_rd8@4 mov [esp + 28], al popad ret @@ -397,24 +406,20 @@ grcgtcr_end: not al and ecx, 3fffh shr ebx, 12 and ebx, byte (3*4) - add ecx, [_extmem + extmem_t.pageptr + ebx] - mov al, [EXTMEMORY + ecx] ; ver0.28 + add ecx, [_i286core + i286core_t.ems + ebx] + mov al, [EXTMEMORY + ecx] pop ecx pop ebx ret ; BIOS or ITF align 16 -@i286_itf: cmp byte [_i286core + i286core_t.itfbank], 0 - jne readmem_itr +@i286_rb: pop ebx + cmp byte [_i286core + i286core_t.itfbank], 0 + jne readmem_itf mov al, [MAINMEMORY + ecx] - pop ebx ret - align 16 -readmem_itr: mov ebx, ecx - and ebx, 00007fffh - mov al, [MAINMEMORY + ITF_ADRS + ebx] - pop ebx +readmem_itf: mov al, [MAINMEMORY + VRAM_STEP + ecx] ret ; ----------------------------------------------------------------- write word @@ -453,6 +458,8 @@ wtramw_a: je short wword_a1fffh jc short wtramw_m cmp ecx, 000a3fffh jnc wcgwindoww_s + test ecx, 2 + je short wtramw_m cmp byte [_gdcs + gdcs_t.msw_accessable], 0 je short wtramw_e wtramw_m: and ebx, 1fffh @@ -614,26 +621,14 @@ grcgwtdw_end: pop ecx ; EGC bridge align 16 @egcw_wt: VRAMTRACE_W + mov ebx, [_vramop + vramop_t.grcgwait] + sub [_i286core + i286core_t.remainclock], ebx pop ebx %if USE_EGCASM - jmp _egca_write_w ; ver0.26 + jmp egc_write_w %else - test ecx, 1 - jne short egcw_wtodd pushad - call @egc_write_w@8 - popad - ret -egcw_wtodd: - pushad - push ecx - push edx - call @egc_write@8 - pop edx - pop ecx - inc ecx - shr edx, 8 - call @egc_write@8 + call @memegc_wr16@8 popad ret %endif @@ -645,12 +640,16 @@ egcw_wtodd: and ecx, 3fffh shr ebx, 12 and ebx, byte (3*4) - add ecx, [_extmem + extmem_t.pageptr + ebx] - mov [EXTMEMORY + ecx], dx ; ver0.28 + add ecx, [_i286core + i286core_t.ems + ebx] + mov [EXTMEMORY + ecx], dx pop ecx pop ebx ret +@i286w_wb: mov [MAINMEMORY + 1c8000h - 0e8000h + ecx], dx + pop ebx + ret + ; ------------------------------------------------------------------ read word ; normal memory @@ -770,38 +769,19 @@ grcgwtcr_end: not ax ; EGC bridge align 16 -@egcw_rd: pop ebx - test ecx, 1 - jne short egcw_rdodd +@egcw_rd: mov ebx, [_vramop + vramop_t.grcgwait] + sub [_i286core + i286core_t.remainclock], ebx + pop ebx %if USE_EGCASM - jmp _egca_read_w ; ver0.26 + jmp egc_read_w %else pushad - call @egc_read_w@4 + call @memegc_rd16@4 mov [esp + 28], ax popad ret %endif -egcw_rdodd: -%if USE_EGCASM ; ver0.26 - inc ecx - call _egca_read - mov ah, al - dec ecx - jmp _egca_read -%else - pushad - push ecx - call @egc_read@4 - pop ecx - mov [esp+28], al - inc ecx - call @egc_read@4 - mov [esp+29], al - popad -%endif - ret ; EMM read align 16 @@ -810,32 +790,46 @@ egcw_rdodd: and ecx, 3fffh shr ebx, 12 and ebx, byte (3*4) - add ecx, [_extmem + extmem_t.pageptr + ebx] - mov ax, [EXTMEMORY + ecx] ; ver0.28 + add ecx, [_i286core + i286core_t.ems + ebx] + mov ax, [EXTMEMORY + ecx] pop ecx pop ebx ret ; BIOS or ITF align 16 -@i286w_itf: cmp byte [_i286core + i286core_t.itfbank], 0 - jne readwmem_itr +@i286w_rb: pop ebx + cmp byte [_i286core + i286core_t.itfbank], 0 + jne readwmem_itf mov ax, [MAINMEMORY + ecx] - pop ebx ret - align 16 -readwmem_itr: mov ebx, ecx - and ebx, 00007fffh - mov ax, [MAINMEMORY + ITF_ADRS + ebx] - pop ebx +readwmem_itf: mov ax, [MAINMEMORY + VRAM_STEP + ecx] ret section .data + ; ---------------------------------------------------------------------- table - global _memory_write global _memory_read + global _memory_write + +_memory_read dd @i286_rd, @i286_rd ; 00 + dd @i286_rd, @i286_rd ; 10 + dd @i286_rd, @i286_rd ; 20 + dd @i286_rd, @i286_rd ; 30 + dd @i286_rd, @i286_rd ; 40 + dd @i286_rd, @i286_rd ; 50 + dd @i286_rd, @i286_rd ; 60 + dd @i286_rd, @i286_rd ; 70 + dd @i286_rd, @i286_rd ; 80 + dd @i286_rd, @i286_rd ; 90 + dd @tram_rd, @vram_r0 ; a0 + dd @vram_r0, @vram_r0 ; b0 + dd @emmc_rd, @emmc_rd ; c0 + dd @i286_rd, @i286_rd ; d0 + dd @vram_r0, @i286_rd ; e0 + dd @i286_rd, @i286_rb ; f0 _memory_write dd @i286_wt, @i286_wt ; 00 dd @i286_wt, @i286_wt ; 10 @@ -854,22 +848,22 @@ _memory_write dd @i286_wt, @i286_wt ; dd @vram_w0, @i286_wn ; e0 dd @i286_wn, @i286_wn ; f0 -_memory_read dd @i286_rd, @i286_rd ; 00 - dd @i286_rd, @i286_rd ; 10 - dd @i286_rd, @i286_rd ; 20 - dd @i286_rd, @i286_rd ; 30 - dd @i286_rd, @i286_rd ; 40 - dd @i286_rd, @i286_rd ; 50 - dd @i286_rd, @i286_rd ; 60 - dd @i286_rd, @i286_rd ; 70 - dd @i286_rd, @i286_rd ; 80 - dd @i286_rd, @i286_rd ; 90 - dd @tram_rd, @vram_r0 ; a0 - dd @vram_r0, @vram_r0 ; b0 - dd @emmc_rd, @emmc_rd ; c0 - dd @i286_rd, @i286_rd ; d0 - dd @vram_r0, @i286_rd ; e0 - dd @i286_rd, @i286_itf ; f0 +_memword_read dd @i286w_rd, @i286w_rd ; 00 + dd @i286w_rd, @i286w_rd ; 10 + dd @i286w_rd, @i286w_rd ; 20 + dd @i286w_rd, @i286w_rd ; 30 + dd @i286w_rd, @i286w_rd ; 40 + dd @i286w_rd, @i286w_rd ; 50 + dd @i286w_rd, @i286w_rd ; 60 + dd @i286w_rd, @i286w_rd ; 70 + dd @i286w_rd, @i286w_rd ; 80 + dd @i286w_rd, @i286w_rd ; 90 + dd @tramw_rd, @vramw_r0 ; a0 + dd @vramw_r0, @vramw_r0 ; b0 + dd @emmcw_rd, @emmcw_rd ; c0 + dd @i286w_rd, @i286w_rd ; d0 + dd @vramw_r0, @i286w_rd ; e0 + dd @i286w_rd, @i286w_rb ; f0 _memword_write dd @i286w_wt, @i286w_wt ; 00 dd @i286w_wt, @i286w_wt ; 10 @@ -888,33 +882,20 @@ _memword_write dd @i286w_wt, @i286w_wt dd @vramw_w0, @i286_wn ; e0 dd @i286_wn, @i286_wn ; f0 -_memword_read dd @i286w_rd, @i286w_rd ; 00 - dd @i286w_rd, @i286w_rd ; 10 - dd @i286w_rd, @i286w_rd ; 20 - dd @i286w_rd, @i286w_rd ; 30 - dd @i286w_rd, @i286w_rd ; 40 - dd @i286w_rd, @i286w_rd ; 50 - dd @i286w_rd, @i286w_rd ; 60 - dd @i286w_rd, @i286w_rd ; 70 - dd @i286w_rd, @i286w_rd ; 80 - dd @i286w_rd, @i286w_rd ; 90 - dd @tramw_rd, @vramw_r0 ; a0 - dd @vramw_r0, @vramw_r0 ; b0 - dd @emmcw_rd, @emmcw_rd ; c0 - dd @i286w_rd, @i286w_rd ; d0 - dd @vramw_r0, @i286w_rd ; e0 - dd @i286w_rd, @i286w_itf ; f0 +section .rdata -_vram_write dd @vram_w0, @vram_w1 ; 00 - dd @vram_w0, @vram_w1 - dd @vram_w0, @vram_w1 ; 40 - dd @vram_w0, @vram_w1 - dd @grcg_tdw0, @grcg_tdw1 ; 80 tdw/tcr - dd @egc_wt, @egc_wt - dd @grcg_rmw0, @grcg_rmw1 ; c0 rmw - dd @egc_wt, @egc_wt +memmap dd @i286_rd, @i286_rb ; NEC + dd @i286_wn, @i286_wn + dd @i286w_rd, @i286w_rb + dd @i286_wn, @i286_wn + + dd @i286_rb, @i286_rb ; EPSON + dd @i286_wt, @i286_wb + dd @i286w_rb, @i286w_rb + dd @i286w_wt, @i286w_wb -_vram_read dd @vram_r0, @vram_r1 ; 00 + +vram_read dd @vram_r0, @vram_r1 ; 00 dd @vram_r0, @vram_r1 dd @vram_r0, @vram_r1 ; 40 dd @vram_r0, @vram_r1 @@ -923,16 +904,16 @@ _vram_read dd @vram_r0, @vram_r1 ; 00 dd @vram_r0, @vram_r1 ; c0 rmw dd @egc_rd, @egc_rd -_vramw_write dd @vramw_w0, @vramw_w1 ; 00 - dd @vramw_w0, @vramw_w1 - dd @vramw_w0, @vramw_w1 ; 40 - dd @vramw_w0, @vramw_w1 - dd @grcgw_tdw0, @grcgw_tdw1 ; 80 tdw/tcr - dd @egcw_wt, @egcw_wt - dd @grcgw_rmw0, @grcgw_rmw1 ; c0 rmw - dd @egcw_wt, @egcw_wt +vram_write dd @vram_w0, @vram_w1 ; 00 + dd @vram_w0, @vram_w1 + dd @vram_w0, @vram_w1 ; 40 + dd @vram_w0, @vram_w1 + dd @grcg_tdw0, @grcg_tdw1 ; 80 tdw/tcr + dd @egc_wt, @egc_wt + dd @grcg_rmw0, @grcg_rmw1 ; c0 rmw + dd @egc_wt, @egc_wt -_vramw_read dd @vramw_r0, @vramw_r1 ; 00 +vramw_read dd @vramw_r0, @vramw_r1 ; 00 dd @vramw_r0, @vramw_r1 dd @vramw_r0, @vramw_r1 ; 40 dd @vramw_r0, @vramw_r1 @@ -941,9 +922,20 @@ _vramw_read dd @vramw_r0, @vramw_r1 ; dd @vramw_r0, @vramw_r1 ; c0 rmw dd @egcw_rd, @egcw_rd +vramw_write dd @vramw_w0, @vramw_w1 ; 00 + dd @vramw_w0, @vramw_w1 + dd @vramw_w0, @vramw_w1 ; 40 + dd @vramw_w0, @vramw_w1 + dd @grcgw_tdw0, @grcgw_tdw1 ; 80 tdw/tcr + dd @egcw_wt, @egcw_wt + dd @grcgw_rmw0, @grcgw_rmw1 ; c0 rmw + dd @egcw_wt, @egcw_wt + + section .text + global @i286_memorymap@4 global @i286_vram_dispatch@4 global @i286_memorywrite@8 @@ -969,7 +961,7 @@ section .text align 16 writeextmem_w: %if USE_HIMEM - cmp ecx, 10ffefh ; HIMEM + cmp ecx, (USE_HIMEM - 1) jae near writehimem_w %endif push ebx @@ -1007,7 +999,7 @@ writemain_b: mov [MAINMEMORY + ecx], d align 16 writeextmem_b: %if USE_HIMEM - cmp ecx, 10fff0h ; HIMEM + cmp ecx, USE_HIMEM jae near writehimem %endif push ebx @@ -1024,7 +1016,7 @@ writeextmem_b: align 16 readmemory_w: %if USE_HIMEM - cmp ecx, 10ffefh ; HIMEM + cmp ecx, (USE_HIMEM - 1) jae near readhimem_w %endif push ebx @@ -1059,7 +1051,7 @@ readmain_b: mov al, [MAINMEMORY + ecx align 16 readmemory_b: %if USE_HIMEM - cmp ecx, 10fff0h ; HIMEM + cmp ecx, USE_HIMEM jae near readhimem %endif push ebx @@ -1082,30 +1074,65 @@ readmemory_b: mov ax, 0ffffh ret + + align 16 +@i286_memorymap@4: and ecx, 1 + shl ecx, 5 + lea ecx, [memmap + ecx] + mov edx, _memory_read + mov eax, [ecx] + mov [edx + 74h], eax + mov [edx + 78h], eax + mov eax, [ecx+4] + mov [edx + 7ch], eax + mov eax, [ecx+8] + mov edx, _memory_write + mov [edx + 68h], eax + mov [edx + 6ch], eax + mov eax, [ecx+12] + mov [edx + 74h], eax + mov [edx + 78h], eax + mov [edx + 7ch], eax + mov eax, [ecx+16] + mov edx, _memword_read + mov [edx + 74h], eax + mov [edx + 78h], eax + mov eax, [ecx+20] + mov [edx + 7ch], eax + mov eax, [ecx+24] + mov edx, _memword_write + mov [edx + 68h], eax + mov [edx + 6ch], eax + mov eax, [ecx+28] + mov [edx + 74h], eax + mov [edx + 78h], eax + mov [edx + 7ch], eax + ret + align 16 @i286_vram_dispatch@4: mov edx, ecx and edx, byte 15 - mov eax, [_vram_write + edx*4] - mov [_memory_write + 54h], eax ; VRAM_B - mov [_memory_write + 58h], eax ; VRAM_R - mov [_memory_write + 5ch], eax ; VRAM_G - mov [_memory_write + 70h], eax ; VRAM_E - mov eax, [_vram_read + edx*4] + mov eax, [vram_read + edx*4] mov [_memory_read + 54h], eax ; VRAM_B mov [_memory_read + 58h], eax ; VRAM_R mov [_memory_read + 5ch], eax ; VRAM_G mov [_memory_read + 70h], eax ; VRAM_E - mov eax, [_vramw_write + edx*4] - mov [_memword_write + 54h], eax ; VRAM_B - mov [_memword_write + 58h], eax ; VRAM_R - mov [_memword_write + 5ch], eax ; VRAM_G - mov [_memword_write + 70h], eax ; VRAM_E - mov eax, [_vramw_read + edx*4] + mov eax, [vram_write + edx*4] + mov [_memory_write + 54h], eax ; VRAM_B + mov [_memory_write + 58h], eax ; VRAM_R + mov [_memory_write + 5ch], eax ; VRAM_G + mov [_memory_write + 70h], eax ; VRAM_E + mov eax, [vramw_read + edx*4] mov [_memword_read + 54h], eax ; VRAM_B mov [_memword_read + 58h], eax ; VRAM_R mov [_memword_read + 5ch], eax ; VRAM_G mov [_memword_read + 70h], eax ; VRAM_E + mov eax, [vramw_write + edx*4] + mov [_memword_write + 54h], eax ; VRAM_B + mov [_memword_write + 58h], eax ; VRAM_R + mov [_memword_write + 5ch], eax ; VRAM_G + mov [_memword_write + 70h], eax ; VRAM_E test ecx, 10h jne short degtaldispatch_e mov eax, @i286_nonram_w@8