From: Robin Krens Date: Fri, 3 Jun 2022 22:09:00 +0000 (+0200) Subject: convert to c phase 1 X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=2e218163530251ce77d29a2a797550b721a8a059;p=swan-dev convert to c phase 1 --- diff --git a/Makefile b/Makefile index ce76b7c..d1f043e 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,10 @@ CC=bcc LD=ld86 AS=nasm +#$(LD) -M src/*.o + all: - $(LD) -M src/*.o + $(LD) src/*.o -d -s -o test.wsc # use -x to for -ffreestanding c-files: @@ -14,6 +16,6 @@ init: $(AS) -fas86 src/*.s -i $(INC) clean: - rm -rf src/*.o + rm -rf src/*.o test.wsc diff --git a/gfx/bgtile.bmp b/gfx/bgtile.bmp new file mode 100644 index 0000000..50edfd5 Binary files /dev/null and b/gfx/bgtile.bmp differ diff --git a/gfx/bgtile.gfx b/gfx/bgtile.gfx new file mode 100644 index 0000000..39da3a3 --- /dev/null +++ b/gfx/bgtile.gfx @@ -0,0 +1 @@ +1"12"1#!1221#!2##112"#" \ No newline at end of file diff --git a/gfx/bgtile.pal b/gfx/bgtile.pal new file mode 100644 index 0000000..c4f127a --- /dev/null +++ b/gfx/bgtile.pal @@ -0,0 +1 @@ +egyŒÿÿÿÿÿÿÿÿÿÿÿÿ \ No newline at end of file diff --git a/src/init.s b/src/init.s index f546c3e..c2b2fbe 100644 --- a/src/init.s +++ b/src/init.s @@ -1,48 +1,194 @@ -;; File : init.s -;; Author : Robin Krens -;; Date : 02.06.2022 -;; Last Modified Date: 02.06.2022 -;; Last Modified By : Robin Krens - - ;;org 0x0000 - cpu 186 - bits 16 - -extern _main - -section .data - %include "init.inc" - -section .text - -init: - cli ; disable interrupts - cld ; offset in increment mode - - xor ax,ax ; clear all registers - mov bx,ax - mov cx,ax - mov dx,ax - mov si,ax - mov di,ax - mov ds,ax ; clear Segments - mov es,ax - - mov bp,ax ; setup stack - mov ss,ax - mov sp,WS_STACK - - in al,IO_HARDWARE_TYPE ; check wonderswan mono or color - test al,WS_COLOR -.mono: jz .mono ;loop forever if mono - - mov sp,WSC_STACK ; new stack - -clear_ram: - xor ax,ax ; clear Ram - mov di,0x100 - mov cx,0x7E80 - rep stosw - - ; call to _main - call _main + +%include "WonderSwan.inc" + +extern _main + +MYSEGMENT equ 0xF000 + +; Set Maps and Sprite Table at the end of first part of ram +fgmap equ WSC_TILE_BANK1-MAP_SIZE +bgmap equ fgmap-MAP_SIZE +sprtable equ bgmap-SPR_TABLE_SIZE + + + cpu 186 + bits 16 + + ;PADDING 15 ; Pad 15 Sections + + section .text + + ;ORG 0x0000 + +..start: + cli ; Disable Interrupts + cld ; Offset in Increment mode + + xor ax,ax ; Clear all registers + mov bx,ax + mov cx,ax + mov dx,ax + mov si,ax + mov di,ax + mov ds,ax ; Clear Segments + mov es,ax + + mov bp,ax ; Setup stack + mov ss,ax + mov sp,WS_STACK + + in al,IO_HARDWARE_TYPE ; Check Wonderswan Mono/Color + test al,WS_COLOR +.mono: jz .mono ; We loop forever if Mono + + mov sp,WSC_STACK ; New stack + + xor ax,ax ; Clear Ram + mov di,0x100 + mov cx,0x7E80 + rep stosw + + out IO_SRAM_BANK,al + + ; Video Init + in al,IO_VIDEO_MODE + or al,VMODE_16C_CHK | VMODE_CLEANINIT + out IO_VIDEO_MODE,al + + xor ax,ax + + out IO_BG_X,al + out IO_BG_Y,al + out IO_FG_X,al + out IO_FG_Y,al + + out IO_SPR_START,al + out IO_SPR_STOP,al + + mov al,BG_MAP(bgmap) | FG_MAP(fgmap) + out IO_FGBG_MAP,al + + mov al,SPR_TABLE(sprtable) + out IO_SPR_TABLE,al + + in al,IO_LCD_CTRL + or al,LCD_ON + out IO_LCD_CTRL,al + + xor al,al + out IO_LCD_ICONS,al + + ; Setup VBlank Int + mov ax,INT_BASE + out IO_INT_BASE,al + + mov di,INTVEC_VBLANK_START + add di,ax + shl di,2 ; *4 + mov word [es:di],VBlank + mov word [es:di+0x2],MYSEGMENT + + xor ax,ax ; Clear HBL & Timer + out IOw_HBLANK_FREQ,ax + out IO_TIMER_CTRL,al + + dec al ; Ack all Int + out IO_INT_ACK,al + + mov al,INT_VBLANK_START ; Enable VBL Int + out IO_INT_ENABLE,al + + sti ; Enable Interrupts ! + +;-------------------------------- + + ; Set Segments for Copy + mov ax,MYSEGMENT + mov ds,ax + xor ax,ax + mov es,ax + + ; Make BG + + mov si,TileGfx + mov di,WSC_TILE_BANK1 + mov cx,(TileGfxE-TileGfx)/2 + rep movsw + + mov si,TilePal + mov di,WSC_PALETTES + mov cx,16 + rep movsw + + mov ax,BG_CHR(0,0,0,0,0) ; Initial Tile, Pal 0, Bank 0 + mov di,bgmap + mov cx,MAP_TWIDTH*MAP_THEIGHT + rep stosw + + ; Display ! + mov al,BG_ON | FG_ON + out IO_DISPLAY_CTRL,al + + ; Loop Read Buttons +loop: + mov al,KEYPAD_READ_BUTTONS + out IO_KEYPAD,al + nop + nop + nop + nop + in al,IO_KEYPAD + + test al,PAD_A ; Press A for Audio + jz loop + + ;call _main + jmp loop + +;****************************************** + +VBlank: + push ax + + mov al,[es:VBLcnt] + inc al + mov [es:VBLcnt],al + and al,3 + jnz .noscroll + + in al,IO_BG_X ; Infinite Scroll + inc al + out IO_BG_X,al + + in al,IO_BG_Y + inc al + out IO_BG_Y,al + +.noscroll: + in al,IO_INT_ACK + or al,INT_VBLANK_START + out IO_INT_ACK,al + + pop ax + iret + +;****************************************** + + align 2 + +TilePal: incbin "gfx/bgtile.pal" +TileGfx: incbin "gfx/bgtile.gfx" +TileGfxE: + +;****************************************** + + ROM_HEADER ..start, MYSEGMENT, 0x42, RH_WS_COLOR, RH_ROM_8MBITS, RH_NO_SRAM, RH_HORIZONTAL + +;****************************************** + + ;section .bss + + ;start=0x0100 ; Keep space for Int Vectors + +VBLcnt: resb 0 ; Our datas in RAM +