Jump to content
IGNORED

Loading Tiles into Graphics Mode 1


Captain Cozmos

Recommended Posts

It's been a while since I shared routines inside the Programing area.  So...

I lifted this out of Space Panic which runs under graphics mode 1.


I thought I would show it just in case any of you plan to make something in the future.

After I optimized this one routine it ran the same but was 10 bytes lighter.  Not that it matters in this day and age.

I did change some labels in order to make the routine generic but you can still use it none the less to load in a set of patterns mixed with ASCII and Number tables

Colors and Sprites as well.

You will have a bit of other setup like calling Mode 1, initializing the tables and such. 

I wanted to share this portion now because I am bogged down with other projects.  Perhaps I will write a complete Mode 1 setup routing and share it down the road.

 

Personally, I don't know why this is not used more often.  I mean seriously, how many games out there use more than 1 color per tile when most of it are simple 1 color backgrounds.

 

Anyway, here is the routine I grabbed and reworked.

 

LOAD_TILES_AND_COLORS_TO_VRAM:
    CALL    LOAD_TILE_PATTERNS_TO_VRAM
    CALL    LOAD_NUMBERS_TO_VRAM_01      ; DONE TWICE FOR DIFFERENT COLORS (MODE 1)
    CALL    LOAD_ASCII_TO_VRAM                ; LOAD IN ASCII
    CALL    LOAD_NUMBERS_TO_VRAM_02      ; DONE TWICE FOR DIFFERENT COLORS (MODE 1)
    CALL    LOAD_COLOR_TABLE_TO_VRAM     ; MODE 1 COLOR TABLE.  EVERY 8 TILES GETS A SINGLE COLOR
    CALL    LOAD_SPRITES_TO_VRAM            ; LOAD SPRITES TO VRAM
RET

 

LOAD_TILE_PATTERNS_TO_VRAM:
    LD      IX, PATTERN_INDEX_TABLE

LOOP_UNTIL_DONE:
    LD      A, (IX+0)                  ; BYTES TO TRANSFER OR $00 TO TERMINATE FROM (IX+0)
    OR A
    RET Z                                ; RETURN IF A IS $00
    LD      B, 0                         ; ZERO OUT B
    LD      C, A                         ; TRANSFER BYTE COUNT TO C
    PUSH    BC                         ; PUSH BC ON THE STACK
    POP     IY                          ; POP ONTO IY FOR HOW MANY BYTES.  IY = BYTE COUNT TO TRANSFER (PUT_VRAM ROUTINE) 
    LD      D, 0                        ; HIGH BYTE OF DE, START INDEX IN VRAM (PUT_VRAM ROUTINE) 
    LD      E, (IX+1)                  ; LOW BYTE OF DE
    LD      H, (IX+3)                  ; HIGH BYTE OF HL, PATTERN TABLE SENDING TO VRAM (PUT_VRAM ROUTINE) 
    LD      L, (IX+2)                  ; LOW BYTE OF HL
    LD      A, 3                         ; 3 = PATTERN GENERATOR TABLE IN VRAM (PUT_VRAM ROUTINE) 
    PUSH    IX
    CALL    PUT_VRAM
    POP     IX
    LD      BC, 4
    ADD     IX, BC
    JR      LOOP_UNTIL_DONE

 

LOAD_NUMBERS_TO_VRAM_01:
    LD      HL, (NUMBER_TABLE)
    LD      DE, $D8                      ; WHERE IN TABLE TO PLACE PATTERN SET
    LD      IY, $0A                      ; 10 NUMBERS, 1-9 PLUS 0
    JR      SEND_PATTERNS_TO_VRAM

 

LOAD_ASCII_TO_VRAM:
    LD      HL, (ASCII_TABLE)
    LD      DE, $E2                      ; WHERE IN TABLE TO PLACE PATTERN SET
    LD      IY, $1A                      ; 26 LETTERS
    JR      SEND_PATTERNS_TO_VRAM

 

LOAD_NUMBERS_TO_VRAM_02:
    LD      HL, (NUMBER_TABLE)
    LD      BC, $FFE0
    ADD     HL, BC
    LD      DE, $FC
    LD      IY, 3
    CALL    SEND_PATTERNS_TO_VRAM
    LD      HL, (NUMBER_TABLE)
    LD      BC, $4E
    ADD     HL, BC
    LD      DE, $FF
    LD      IY, 1

 

SEND_PATTERNS_TO_VRAM:
    LD      A, 3                         ; 3 = PATTERN GENERATOR TABLE
    JP      PUT_VRAM

 

LOAD_COLOR_TABLE_TO_VRAM:
    LD      HL, COLOR_TABLE
    LD      DE, $00
    LD      IY, $20
    LD      A, 4                         ; 4 = COLOR TABLE
    JP      PUT_VRAM

 

LOAD_SPRITES_TO_VRAM:
    LD      HL, SPRITE_PATTERNS
    LD      DE, $00
    LD      IY, $D8
    LD      A, 01                        ; 1 = SPRITE TABLE
    JP      PUT_VRAM                 ; JUMP INSTEAD OF CALL WILL RETURN OUT OF SUBROUTINE.  USE CALL TO PROCEED TO THE NEXT STATEMENT.

 

PATTERN_INDEX_TABLE:
    DB $01
    DB $00
    DW BLANK_PATTERN              ; FIRST CHARACTER IS BLANK AND COLOR 0, OTHERWISE AREAS ON THE SCREEN THAT USE A SPACE WILL HAVE A PATTERN, COLOR OR BOTH.
    DB $0D                               ; NUMBER OF PATTERNS
    DB $08                               ; WHERE IN TABLE TO PLACE PATTERN SET
    DW PATTERN_SET_01            ; PATTERN SET
    DB $02
    DB $18
    DW PATTERN_SET_02
    DB $02                               ; EXAMPLE NUMBER OF PATTERNS FOR THIS ROUTINE.  MUST BE MULTIPLES OF 8 FOR MODE 1.
    DB $20                               ; EXAMPLE LOCATION IN PATTERN TABLE FOR THIS ROUTINE.
    DW PATTERN_SET_03
    DB $0A
    DB $28
    DW PATTERN_SET_04
    DB $02
    DB $38
    DW PATTERN_SET_05
    DB $02
    DB $40
    DW PATTERN_SET_06
    DB $1B
    DB $48
    DW PATTERN_SET_07
    DB $08
    DB $70
    DW PATTERN_SET_08
    DB $00                                   ; END WITH $00 TO IDENTIFY THE END OF THE TABLE.

 

COLOR_TABLE:                             ; EXAMPLE COLOR TABLE FOR THIS ROUTINE.  1 BYTE FOR EVERY 8 TILES WHEN USING MODE 1.
    DB 000,080,080,176,033,096,096,208   ; 1ST BYTE MUST BE ZERO OR ANY AREA ON SCREEN THAT USES A SPACE WILL HAVE A PATTERN, COLOR OR BOTH.
    DB 208,018,018,018,018,018,176,176
    DB 033,033,033,033,033,033,033,033
    DB 033,033,033,241,241,241,241,241

 

 

 

O3 Cozmos

Edited by Captain Cozmos
  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

Thanks for the help guys..

Here we have different color background tiles along with my 16x16 sprites

 

The background color table is 32 bytes and sets the color of groups of 8 characters in ram ..not the screen location as i was thinking..

COLEBG.jpg

Edited by MrDave
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...