Skip to content

Commit

Permalink
Merge branch 'optimize' of https://github.com/Drenn1/wla-dx
Browse files Browse the repository at this point in the history
  • Loading branch information
vhelin committed Feb 5, 2016
2 parents 4a16754 + a5014ec commit d24982e
Show file tree
Hide file tree
Showing 31 changed files with 1,800 additions and 613 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -76,7 +76,7 @@ add_subdirectory (wlab)
add_subdirectory (wlalink)

# --- WLA executables ---
set(CFILES main.c parse.c include_file.c pass_1.c pass_2.c pass_3.c pass_4.c stack.c listfile.c)
set(CFILES main.c hashmap.c parse.c include_file.c pass_1.c pass_2.c pass_3.c pass_4.c stack.c listfile.c)

# GB
add_executable(wla-gb ${CFILES})
Expand Down
2 changes: 2 additions & 0 deletions FILE_FORMATS
Expand Up @@ -127,6 +127,7 @@ section:
n name (terminated with 0 (free), 1 (forced), 2 (overwrite), 3 (header),
4 (semifree), 5 (absolute), 6 (ram),
7 (superfree) or 8 (semisubfree))
n namespace (terminated with 0)
4 section id (int)
1 slot number (0-255)
1 file id
Expand Down Expand Up @@ -215,6 +216,7 @@ sections:

...
n name (terminated with 0 (for free) or 7 (for superfree))
n namespace (terminated with 0)
4 section id (int)
1 file id
4 number of bytes (int)
Expand Down
9 changes: 9 additions & 0 deletions README
Expand Up @@ -2084,6 +2084,13 @@ output mode. Library file's sections must all be FREE ones. .BANK tells
the bank number where this section will be later relocated into. .ORG
tells the offset for the relocation from the beginning of .BANK.

You can put sections inside a namespace. For instance, if you put a section
into a namespace called "bank0", then labels in that section can be
accessed with "bank0.label". This is not necessary inside the section
itself. The namespace directive should immediately follow the name.

.SECTION "Init" NAMESPACE "bank0"

You can supply the preferred section size (bytes) inside the section
name string. Here's an example:

Expand Down Expand Up @@ -3477,6 +3484,8 @@ smail: Ville Helin
- Zachary Keene for writing .SNESHEADER, .ENDSNES, .SNESNATIVEVECTOR,
.ENDNATIVEVECTOR, .SNESEMUVECTOR and .ENDEMUVECTOR. I want more
people like him! ;)
- Matthew Stewart for implementing namespaces and speeding up WLA with
hashmaps.
- People at gameboy@vip.co.za, gameboydev@listbot.com,
gbadev@yahoogroups.com and s8-dev for keeping up the good work! ;)

Expand Down
10 changes: 9 additions & 1 deletion defines.h
@@ -1,3 +1,4 @@
#include "hashmap.h"

#ifndef _DEFINES_H
#define _DEFINES_H
Expand Down Expand Up @@ -416,7 +417,6 @@ struct definition {
double value;
int type;
int size;
struct definition *next;
};

struct macro_argument {
Expand Down Expand Up @@ -479,6 +479,7 @@ struct label_def {
#endif
int filename_id;
int linenumber;
struct section_def *section_struct;
struct label_def *next;
};

Expand All @@ -501,9 +502,16 @@ struct section_def {
int *listfile_ints;
char *listfile_cmds;
unsigned char *data;
struct namespace_def *nspace;
struct map_t *label_map;
struct section_def *next;
};

struct namespace_def {
char name[MAX_NAME_LENGTH];
struct map_t *label_map;
};

struct incbin_file_data {
struct incbin_file_data *next;
char *data;
Expand Down
116 changes: 116 additions & 0 deletions examples/gb-z80/namespace_test/cgb_hardware.i
@@ -0,0 +1,116 @@

;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
; colour gameboy hardware register definitions
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

.DEFINE P1 $FF00
.DEFINE SB $FF01
.DEFINE SC $FF02
.DEFINE DIV $FF04
.DEFINE TIMA $FF05
.DEFINE TMA $FF06
.DEFINE TAC $FF07
.DEFINE IF $FF0F
.DEFINE NR10 $FF10
.DEFINE NR11 $FF11
.DEFINE NR12 $FF12
.DEFINE NR13 $FF13
.DEFINE NR14 $FF14
.DEFINE NR21 $FF16
.DEFINE NR22 $FF17
.DEFINE NR23 $FF18
.DEFINE NR24 $FF19
.DEFINE NR30 $FF1A
.DEFINE NR31 $FF1B
.DEFINE NR32 $FF1C
.DEFINE NR33 $FF1D
.DEFINE NR34 $FF1E
.DEFINE NR41 $FF20
.DEFINE NR42 $FF21
.DEFINE NR43 $FF22
.DEFINE NR44 $FF23
.DEFINE NR50 $FF24
.DEFINE NR51 $FF25
.DEFINE NR52 $FF26
.DEFINE LCDC $FF40
.DEFINE STAT $FF41
.DEFINE SCY $FF42
.DEFINE SCX $FF43
.DEFINE LY $FF44
.DEFINE LYC $FF45
.DEFINE DMA $FF46
.DEFINE BGP $FF47
.DEFINE OBP0 $FF48
.DEFINE OBP1 $FF49
.DEFINE WY $FF4A
.DEFINE WX $FF4B
.DEFINE KEY1 $FF4D
.DEFINE VBK $FF4F
.DEFINE HDMA1 $FF51
.DEFINE HDMA2 $FF52
.DEFINE HDMA3 $FF53
.DEFINE HDMA4 $FF54
.DEFINE HDMA5 $FF55
.DEFINE RP $FF56
.DEFINE BCPS $FF68
.DEFINE BCPD $FF69
.DEFINE OCPS $FF6A
.DEFINE OCPD $FF6B
.DEFINE SVBK $FF70
.DEFINE IE $FFFF

.DEFINE R_P1 $00
.DEFINE R_SB $01
.DEFINE R_SC $02
.DEFINE R_DIV $04
.DEFINE R_TIMA $05
.DEFINE R_TMA $06
.DEFINE R_TAC $07
.DEFINE R_IF $0F
.DEFINE R_NR10 $10
.DEFINE R_NR11 $11
.DEFINE R_NR12 $12
.DEFINE R_NR13 $13
.DEFINE R_NR14 $14
.DEFINE R_NR21 $16
.DEFINE R_NR22 $17
.DEFINE R_NR23 $18
.DEFINE R_NR24 $19
.DEFINE R_NR30 $1A
.DEFINE R_NR31 $1B
.DEFINE R_NR32 $1C
.DEFINE R_NR33 $1D
.DEFINE R_NR34 $1E
.DEFINE R_NR41 $20
.DEFINE R_NR42 $21
.DEFINE R_NR43 $22
.DEFINE R_NR44 $23
.DEFINE R_NR50 $24
.DEFINE R_NR51 $25
.DEFINE R_NR52 $26
.DEFINE R_LCDC $40
.DEFINE R_STAT $41
.DEFINE R_SCY $42
.DEFINE R_SCX $43
.DEFINE R_LY $44
.DEFINE R_LYC $45
.DEFINE R_DMA $46
.DEFINE R_BGP $47
.DEFINE R_OBP0 $48
.DEFINE R_OBP1 $49
.DEFINE R_WY $4A
.DEFINE R_WX $4B
.DEFINE R_KEY1 $4D
.DEFINE R_VBK $4F
.DEFINE R_HDMA1 $51
.DEFINE R_HDMA2 $52
.DEFINE R_HDMA3 $53
.DEFINE R_HDMA4 $54
.DEFINE R_HDMA5 $55
.DEFINE R_RP $56
.DEFINE R_BCPS $68
.DEFINE R_BCPD $69
.DEFINE R_OCPS $6A
.DEFINE R_OCPD $6B
.DEFINE R_SVBK $70
.DEFINE R_IE $FF
15 changes: 15 additions & 0 deletions examples/gb-z80/namespace_test/defines1.i
@@ -0,0 +1,15 @@

;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
; universal defines
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

.NAME "WLA TEST ROM"
.RAMSIZE 0
.EMPTYFILL $00 ;ret.
.CARTRIDGETYPE 1
.LICENSEECODEOLD $1A
.COMPUTECHECKSUM
.COMPUTECOMPLEMENTCHECK

.PRINTT WLA_FILENAME
.PRINTT "\n"
11 changes: 11 additions & 0 deletions examples/gb-z80/namespace_test/defines2.i
@@ -0,0 +1,11 @@

;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
; universal defines
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

.RAMSIZE 0
.EMPTYFILL $C9 ;ret.
.CARTRIDGETYPE 1
.LICENSEECODEOLD $1A
.COMPUTECHECKSUM
.COMPUTECOMPLEMENTCHECK
14 changes: 14 additions & 0 deletions examples/gb-z80/namespace_test/gb_memory1.i
@@ -0,0 +1,14 @@

;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
; game boy ROM memory map for MBC1-5
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

.MEMORYMAP
SLOTSIZE $4000
DEFAULTSLOT 1
SLOT 0 $0000
SLOT 1 $4000
.ENDME

.ROMBANKSIZE $4000
.ROMBANKS 4
3 changes: 3 additions & 0 deletions examples/gb-z80/namespace_test/linkfile
@@ -0,0 +1,3 @@
[objects]
setup.o
main.o
94 changes: 94 additions & 0 deletions examples/gb-z80/namespace_test/main.s
@@ -0,0 +1,94 @@

;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
; This example means to test "namespaces" in wla-dx. Including "masking",
; discarding, etc...
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

.OUTNAME "main.o"

;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
; project includes
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

.incdir "bogus"
.INCLUDE "gb_memory1.i"
.incdir ""
.INCLUDE "defines1.i"
.include "cgb_hardware.i"

;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
; main
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

.BANK 0 SLOT 0
.ORG $150

.SECTION "Beginning [NO]" FORCE

MAIN:DI
LD SP, stack_ptr-1 ;stack_ptr is defined in setup.s
LD A, 'C' - 10
SUB A
LD ($FF00+R_IE), A ;no interrupts at all.

LD A, 144
LDH (R_WY), A ;window y.

LD A, %10000001
LDH [R_LCDC], A ;lcd control.

SUB A

call s1.func1
call s1.func2
call func3
call func4
call s3.func3
call shared.sharedFunc
call shared.sharedEntry
call _globalFunc

/*
; Uncomment for some errors
call sharedFunc
call sharedEntry
call shared._localFunc
*/

ld hl,_LOOP
push hl
ld hl,data
ldi a,(hl)
ld h,(hl)
ld l,a
ld b,20
-
dec hl
dec b
jr nz,-
jp hl

_LOOP: LD ($FF00+R_BGP), A ;background palette.
INC A
JP _LOOP

data:
.dw s3.func3 + 20 ; Test arithmetic on namespaces


.ENDS

.SECTION "Second part of shared namespace" namespace "shared"

sharedEntry:
call sharedFunc
; Uncomment for an error
; call _localFunc
ret

_globalFunc: ; Should not be called
jr _globalFunc
.ENDS

_globalFunc:
ret
25 changes: 25 additions & 0 deletions examples/gb-z80/namespace_test/makefile
@@ -0,0 +1,25 @@

CC = ../../../binaries/wla-gb
CFLAGS = -ox
LD = ../../../binaries/wlalink
LDFLAGS = -dvs

SFILES = setup.s main.s
IFILES = defines1.i defines2.i
OFILES = main.o setup.o

all: $(OFILES) makefile
$(LD) $(LDFLAGS) linkfile linked.gb

main.o: main.s defines1.i gb_memory1.i
$(CC) $(CFLAGS) main.s

setup.o: setup.s defines2.i gb_memory1.i
$(CC) $(CFLAGS) setup.s


$(OFILES): $(HFILES)


clean:
rm -f $(OFILES) core *~ linked.gb linked.sym

0 comments on commit d24982e

Please sign in to comment.