Skip to content

Commit

Permalink
CORE: Restructured data for save/load states
Browse files Browse the repository at this point in the history
  • Loading branch information
cidoca committed Apr 17, 2014
1 parent f9699a5 commit 0e34308
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 154 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2014-04-16 Cidorvan Leite <cidorvan@gmail.com>

* CORE: Restructured data for save/load states.

2014-04-14 Cidorvan Leite <cidorvan@gmail.com>

* UI: Added support to rewind the game.
Expand Down
10 changes: 5 additions & 5 deletions core.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@
// Banks
void init_banks(int ROM_size);
extern unsigned char battery, *pBank0, *pBank1, *pBank2, *pBank2ROM;
extern unsigned char *ROM, RAM[], RAM_EX[];
extern unsigned char *ROM, RAM_EX[];

// CPU
void reset_CPU();
void int_NMI();
extern unsigned char Flag;

// IO
extern unsigned char Nationalization, Joy1, Joy2;
extern unsigned char Joy1, Joy2;

// PSG
void reset_PSG();
void make_PSG(void *udata, unsigned char *stream, int len);
extern unsigned char rVol1;

// VDP
void reset_VDP();
void scan_frame(void *buffer);
extern unsigned char VDPR;
extern unsigned char VDPStatus;

// Surface
void write_frame(void *surface, int bpp);

// Text
void draw_text(void *surface, int x, int y, char *text, unsigned int color);

// Core data
extern unsigned char pData[], pDataEnd[], pDataXEnd[];
2 changes: 1 addition & 1 deletion core/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AR=ar
ASM=nasm
OBJECTS=banks.o cpu.o io.o psg.o vdp.o text.o
OBJECTS=banks.o cpu.o data.o io.o psg.o vdp.o text.o

libcore.a: $(OBJECTS)
@echo Generating static library $@
Expand Down
23 changes: 3 additions & 20 deletions core/banks.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; Alis, A SEGA Master System emulator
; Copyright (C) 2002-2013 Cidorvan Leite
; Copyright (C) 2002-2014 Cidorvan Leite

; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
Expand All @@ -16,6 +16,7 @@


EXTERN init_battery
%INCLUDE "data.inc"

SECTION .text

Expand Down Expand Up @@ -165,25 +166,7 @@ WM8: test BYTE [RAMSelect], 8

SECTION .bss

; Posição inválida para escrita
GLOBAL garbage
GLOBAL garbage, ROM_size, ROM
garbage RESW 1

; BYTE [battery] em uso
GLOBAL battery
battery RESB 1

; Bancos de paginação
GLOBAL RAMSelect, pBank0, pBank1, pBank2, pBank2ROM
RAMSelect RESB 1
pBank0 RESD 1
pBank1 RESD 1
pBank2 RESD 1
pBank2ROM RESD 1

; NEAR [RAM] e DWORD [ROM]
GLOBAL ROM_size, ROM, RAM, RAM_EX
ROM_size RESB 1
ROM RESD 1
RAM RESB 8*1024
RAM_EX RESB 2*16*1024
46 changes: 2 additions & 44 deletions core/cpu.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; Alis, A SEGA Master System emulator
; Copyright (C) 2002-2013 Cidorvan Leite
; Copyright (C) 2002-2014 Cidorvan Leite

; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
Expand All @@ -19,6 +19,7 @@ EXTERN ?OpCodeErr1@@YAXHH@Z
EXTERN ?OpCodeErr2@@YAXHHH@Z
EXTERN ?OpCodeErr3@@YAXHHHH@Z

%INCLUDE "data.inc"
%INCLUDE "banks.inc"
%INCLUDE "io.inc"

Expand Down Expand Up @@ -3989,46 +3990,3 @@ OpcodeFDCB:
DD _NIMP3, _NIMP3, _NIMP3, _NIMP3, _NIMP3, _NIMP3, _SET5_IYd,_NIMP3 ; E
DD _NIMP3, _NIMP3, _NIMP3, _NIMP3, _NIMP3, _NIMP3, _SET6_IYd,_NIMP3
DD _NIMP3, _NIMP3, _NIMP3, _NIMP3, _NIMP3, _NIMP3, _SET7_IYd,_NIMP3 ; F



SECTION .bss

; Registradores ativos e passivos
GLOBAL Flag, rAcc, rC, rB, rE, rD, rL, rH
GLOBAL Flag2, rAcc2, rC2, rB2, rE2, rD2, rL2, rH2
GLOBAL rR, rI
Flag RESB 1
rAcc RESB 1
Flag2 RESB 1
rAcc2 RESB 1
rC RESB 1
rB RESB 1
rC2 RESB 1
rB2 RESB 1
rE RESB 1
rD RESB 1
rE2 RESB 1
rD2 RESB 1
rL RESB 1
rH RESB 1
rL2 RESB 1
rH2 RESB 1
rR RESB 1
rI RESB 1

; Ponteiros
GLOBAL rIX, rIY, rPCx, rSPx
rIX RESD 1
rIY RESD 1
rPCx RESD 1
rSPx RESD 1

; Interrupções
GLOBAL TClock, IM, IFF1, IFF2, NMI
TClock RESB 1
IM RESB 1
IFF1 RESB 1
IFF2 RESB 1
Halt RESB 1
NMI RESB 1
115 changes: 115 additions & 0 deletions core/data.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
; Alis, A SEGA Master System emulator
; Copyright (C) 2002-2014 Cidorvan Leite

; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.

; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.

; You should have received a copy of the GNU General Public License
; along with this program. If not, see [http://www.gnu.org/licenses/].


SECTION .bss

; **** BANKS ****
GLOBAL pData, pBank0, pBank1, pBank2, pBank2ROM, battery, RAMSelect
pData: ; Alias for start pointer for state block
pBank0 RESD 1
pBank1 RESD 1
pBank2 RESD 1
pBank2ROM RESD 1
battery RESB 1
RAMSelect RESB 1


; **** CPU ****
; Primary and secondary registers
GLOBAL Flag, rAcc, rC, rB, rE, rD, rL, rH
GLOBAL Flag2, rAcc2, rC2, rB2, rE2, rD2, rL2, rH2
GLOBAL rR, rI
Flag RESB 1
rAcc RESB 1
Flag2 RESB 1
rAcc2 RESB 1
rC RESB 1
rB RESB 1
rC2 RESB 1
rB2 RESB 1
rE RESB 1
rD RESB 1
rE2 RESB 1
rD2 RESB 1
rL RESB 1
rH RESB 1
rL2 RESB 1
rH2 RESB 1
rR RESB 1
rI RESB 1

; Pointers
GLOBAL rIX, rIY, rPCx, rSPx
rIX RESD 1
rIY RESD 1
rPCx RESD 1
rSPx RESD 1

; Interruptions
GLOBAL TClock, IM, IFF1, IFF2, Halt, NMI
TClock RESB 1
IM RESB 1
IFF1 RESB 1
IFF2 RESB 1
Halt RESB 1
NMI RESB 1


; **** IO ****
GLOBAL Nationalization
Nationalization RESB 1


; **** PSG ****
; Sound registers
GLOBAL rVol1, rVol2, rVol3, rVol4, rFreq1, rFreq2, rFreq3, rFreq4, rLast
rVol1 RESB 1
rVol2 RESB 1
rVol3 RESB 1
rVol4 RESB 1
rFreq1 RESD 1
rFreq2 RESD 1
rFreq3 RESD 1
rFreq4 RESD 1
rLast RESD 1

; Noise state
GLOBAL Noise, FeedBack, NoiseFreq2
Noise RESD 1
FeedBack RESD 1
NoiseFreq2 RESB 1


; **** VDP ****
GLOBAL VDPStatus, cVDP, VDPLow
VDPStatus RESB 1 ; Status do VDP
cVDP RESB 1 ; Primeira ou segunda escrita na porta BFh
VDPLow RESB 1 ; Valor auxiliar de escrita na porta BFh

GLOBAL pRAM, VDPR, CRAM, VRAM
pRAM RESD 1 ; Pointer for palette or video memory
VDPR RESB 16 ; Video registers
CRAM RESB 32 ; Color palette
VRAM RESB 4000h ; Video memory


; **** MEMORY ****
GLOBAL RAM, pDataEnd, RAM_EX, pDataXEnd
RAM RESB 8*1024
pDataEnd: ; Alias for end pointer for state block
RAM_EX RESB 2*16*1024
pDataXEnd: ; Alias for end pointer with extra memory block
38 changes: 38 additions & 0 deletions core/data.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
; Alis, A SEGA Master System emulator
; Copyright (C) 2002-2014 Cidorvan Leite

; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.

; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.

; You should have received a copy of the GNU General Public License
; along with this program. If not, see [http://www.gnu.org/licenses/].

; **** BANKS ****
EXTERN pBank0, pBank1, pBank2, pBank2ROM, battery, RAMSelect

; **** CPU ****
EXTERN Flag, rAcc, rC, rB, rE, rD, rL, rH
EXTERN Flag2, rAcc2, rC2, rB2, rE2, rD2, rL2, rH2
EXTERN rR, rI, rIX, rIY, rPCx, rSPx
EXTERN TClock, IM, IFF1, IFF2, Halt, NMI

; **** IO ****
EXTERN Nationalization

; **** PSG ****
EXTERN rVol1, rVol2, rVol3, rVol4, rFreq1, rFreq2, rFreq3, rFreq4, rLast
EXTERN Noise, FeedBack, NoiseFreq2

; **** VDP ****
EXTERN VDPStatus, cVDP, VDPLow
EXTERN pRAM, VDPR, CRAM, VRAM

; **** MEMORY ****
EXTERN RAM, RAM_EX
6 changes: 2 additions & 4 deletions core/io.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; Alis, A SEGA Master System emulator
; Copyright (C) 2002-2013 Cidorvan Leite
; Copyright (C) 2002-2014 Cidorvan Leite

; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
Expand All @@ -15,6 +15,7 @@
; along with this program. If not, see [http://www.gnu.org/licenses/].


%INCLUDE "data.inc"
%INCLUDE "cpu.inc"
%INCLUDE "vdp.inc"
%INCLUDE "psg.inc"
Expand Down Expand Up @@ -303,9 +304,6 @@ write_io:

SECTION .bss

GLOBAL Nationalization
Nationalization RESB 1

; Portas do joystick
GLOBAL Joy1, Joy2
Joy1 RESB 1
Expand Down
24 changes: 4 additions & 20 deletions core/psg.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; Alis, A SEGA Master System emulator
; Copyright (C) 2002-2013 Cidorvan Leite
; Copyright (C) 2002-2014 Cidorvan Leite

; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
Expand All @@ -18,6 +18,8 @@
FREQUENCE EQU 44160
BUFFERSIZE EQU FREQUENCE / 60

%INCLUDE "data.inc"

SECTION .text

; * Reseta o som
Expand Down Expand Up @@ -375,25 +377,7 @@ Frequencia:

SECTION .bss

; Registradores de som
GLOBAL rVol1, rVol2, rVol3, rVol4, rFreq1, rFreq2, rFreq3, rFreq4, rLast
rVol1 RESB 1
rVol2 RESB 1
rVol3 RESB 1
rVol4 RESB 1
rFreq1 RESD 1
rFreq2 RESD 1
rFreq3 RESD 1
rFreq4 RESD 1
rLast RESD 1

; Ruído
GLOBAL Noise, FeedBack, NoiseFreq2
Noise RESD 1
FeedBack RESD 1
NoiseFreq2 RESB 1

; Períodos dos canais
; Channels period
GLOBAL Sinal, Periodo1, Periodo2, Periodo3, Periodo4
Sinal RESB 1
Periodo1 RESD 1
Expand Down
Loading

0 comments on commit 0e34308

Please sign in to comment.