Skip to content

Commit

Permalink
Add asm formatting to code example markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
lajohnston committed Jun 25, 2023
1 parent 04bc762 commit 3e00a3c
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 87 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Low-level Sega Master System libs for the WLA-DX Z80 assembler (v10.3+). Its aim

## Quick Start

```
```asm
.incdir "lib/smslib" ; set the working directory to the smslib directory
.include "smslib.asm" ; include the libs
Expand Down
32 changes: 16 additions & 16 deletions docs/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Use `input.readPort1` or `input.readPort2` to capture the input from joypad 1 an

In order to use `input.readPort2` you will need to enable the `input.ENABLE_PORT_2` setting.

```
```asm
.define input.ENABLE_PORT_2
; ... .include smslib or this module
```
Expand All @@ -18,7 +18,7 @@ In order to use `input.readPort2` you will need to enable the `input.ENABLE_PORT

Allows an if-like syntax for detecting when certain buttons have been pressed. If the given button has been pressed, the code inside the 'block' will run, otherwise it will be skipped.

```
```asm
input.readPort1 ; you can also use input.readPort2
input.if input.LEFT, +
Expand All @@ -32,7 +32,7 @@ input.if input.BUTTON_1, +

The following buttons can be checked:

```
```asm
input.UP
input.DOWN
input.LEFT
Expand All @@ -43,7 +43,7 @@ input.BUTTON_2

You can also pass multiple buttons to check if all are currently pressed.

```
```asm
input.if input.BUTTON_1, input.BUTTON_2, +
; Both button 1 and button 2 are pressed
+:
Expand All @@ -57,15 +57,15 @@ input.if input.UP, input.BUTTON_1, input.BUTTON_2, +

Detects if a button has been pressed for both this frame and the previous frame.

```
```asm
input.ifHeld, input.BUTTON_1, +
; BUTTON_1 has been pressed for both frames
+:
```

You can also pass multiple buttons to check if all have been held since the previous frame.

```
```asm
input.ifHeld input.BUTTON_1, input.BUTTON_2, +
; Both button 1 and button 2 are held
+:
Expand All @@ -79,15 +79,15 @@ input.ifHeld input.UP, input.BUTTON_1, input.BUTTON_2, +

Detects if a button was pressed this frame. This will only occur once every time the button is pressed.

```
```asm
input.ifPressed, input.BUTTON_1, +
; BUTTON_1 was just pressed this frame
+:
```

You can provide multiple buttons to detect when all are pressed. This will occur on the first frame in which all buttons are pressed, then not again until any of the buttons are released and pressed again. Note: the buttons don't all have to be pressed on the exact same frame.

```
```asm
input.ifPressed, input.BUTTON_1, input.BUTTON_2, +
; Both buttons have been pressed
+:
Expand All @@ -101,15 +101,15 @@ input.ifPressed, input.UP, input.BUTTON_1, input.BUTTON_2, +

Detects if a button was pressed last frame but is now released. This will only occur once every time the button is released.

```
```asm
input.ifReleased, input.BUTTON_1, +
; BUTTON_1 was pressed but was just released this frame
+:
```

You can provide multiple buttons to detect when multiple buttons were pressed down last time, but now not all of them are. This will occur for one frame.

```
```asm
input.ifReleased, input.BUTTON_1, input.BUTTON_2, +
; Both buttons were pressed last frame, but now one or both aren't
+:
Expand All @@ -125,7 +125,7 @@ These detect if a direction on the given axis is currently pressed and jumps to

This is more efficient that checking each button on the axis individually as the input only needs to be read from the buffer once, and if one is confirmed to be pressed the other check can be skipped.

```
```asm
input.ifXDir left, right, +
left:
; Left is currently pressed
Expand All @@ -149,7 +149,7 @@ These detect if a direction on the given axis was pressed in the last frame and

This is more efficient that checking each button on the axis individually as the input only needs to be read from the buffer once, and if one is confirmed to be pressed the other check can be skipped.

```
```asm
input.ifXDirHeld left, right, +
left:
; Left is currently held
Expand All @@ -173,7 +173,7 @@ These detect if a direction on the given axis has just been pressed this frame,

This is more efficient that checking each button on the axis individually as the input only needs to be read from the buffer once, and if one is confirmed to be pressed the other check can be skipped.

```
```asm
input.ifXDirPressed, left, right, +
left:
; Left has just been pressed
Expand All @@ -195,7 +195,7 @@ input.ifYDirPressed, up, down, +

These detect if a direction on the given axis has just been released this frame, and jump to the relevant label if it has. This is more efficient that checking each button on the axis individually as the input only needs to be read from the buffer once.

```
```asm
input.ifXDirReleased, left, right, +
left:
; Left has just been released
Expand All @@ -217,7 +217,7 @@ input.ifYDirReleased, up, down, +

Loads register A with the directional x-axis: -1 = left, 1 = right, none = 0. An optional multiplier multiplies this result at assemble time.

```
```asm
input.readPort1
input.loadADirX ; left = -1, right = 1, none = 0
Expand All @@ -231,7 +231,7 @@ input.loadADirX -1 ; left = 1, right = -1, none = 0

Loads register A with the directional y-axis: -1 = up, 1 = down, none = 0. An optional multiplier multiplies this result at assemble time.

```
```asm
input.readPort1
input.loadADirX ; up = -1, down = 1, none = 0
Expand Down
20 changes: 10 additions & 10 deletions docs/interrupts.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ You will need to enable interrupts in both the VDP and Z80. After you initialise

You can use [vdp.asm](./vdp.md) for this, taking care not to overwrite any other flags that are also stored within these registers (see `vdp.asm` file for documentation):

```
```asm
vdp.enableHBlank
vdp.enableVBlank
```

You also need to enable interrupts within the Z80 CPU:

```
```asm
interrupts.enable
```

Expand All @@ -28,22 +28,22 @@ VBlanks occur each time the VDP has finished drawing a frame (50 times a second

Enable the VBlank handler by defining `interrupts.HANDLE_VBLANK` setting before including `interrupts.asm`:

```
```asm
.define interrupts.HANDLE_VBLANK 1
.include "interrupts.asm"
```

You will also need to define an `interrupts.onVBlank` label that the handler will jump to when a VBlank occurs. This handler must end with a macro call to `interrupts.endVBlank`:

```
```asm
interrupts.onVBlank:
... ; write data to VRAM
interrupts.endVBlank ; return from VBlank
```

VBlanks can also be used to regulate the speed of your game logic. Place `interrupts.waitForVBlank` in your game loop to ensure the logic doesn't update too quickly.

```
```asm
gameLoop:
interrupts.waitForVBlank
... update logic
Expand All @@ -56,30 +56,30 @@ HBlanks occur when the line counter in the VDP falls below zero. This counter is

Enable the HBlank handler by defining `interrupts.HANDLE_HBLANK` setting before including `interrupts.asm`:

```
```asm
; Note: you can also enable interrupts.HANDLE_VBLANK alongside this if you wish
.define interrupts.HANDLE_HBLANK 1
.include "interrupts.asm"
```

You will also need to define an `interrupts.onHBlank` label that the handler will jump to when an HBlank occurs. This handler must end with a macro call to `interrupts.endHBlank`:

```
```asm
interrupts.onHBlank:
...
interrupts.endHBlank ; return from HBlank
```

The HBlank won't trigger unless the line interval has been set. This takes a zero-based value:

```
```asm
interrupts.setLineInterval 1 ; trigger HBlank every line (lines 0, 1, 2...)
interrupts.setLineInterval 10 ; trigger every 10th line (lines 9, 19, 29...)
```

This can also be set dynamically from `a` by omitting the argument. When using this method the value in `a` must be 0-based:

```
```asm
; Trigger every 20th line
ld a, 19
interrupts.setLineInterval
Expand All @@ -89,6 +89,6 @@ Please note that if you change the interval during active screen time, the new i

You can read the current line being drawn. The value will be loaded into `a`

```
```asm
interrupts.getLine
```
12 changes: 6 additions & 6 deletions docs/mappers.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Mappers define one or more fixed-sized 'slots' that can provide access to a smal

SMSLib will default to using a basic 48KB mapper which is small enough to not require any paging. If you require a larger ROM than this then you can choose another one by including it before `smslib.asm`:

```
```asm
.incdir "lib/smslib" ; point to smslib directory
.include "mapper/sega.asm" ; use sega mapper
.include "smslib.asm" ; include rest of smslib
Expand All @@ -18,7 +18,7 @@ SMSLib will default to using a basic 48KB mapper which is small enough to not re

Only one mapper can be used per project. All mappers expose `FIXED_SLOT`, `PAGE_SLOT_A`, `PAGE_SLOT_B` and `RAM_SLOT` constants. Using these constants should make it easier for you to swap out a mapper at a later stage of development if you decide to do so.

```
```asm
; Pageable slots are good for asset data that is only needed at certain times
.slot mapper.PAGE_SLOT_A
.include "assets.asm" ; contents can now be paged into PAGE_SLOT_A
Expand All @@ -37,16 +37,16 @@ Only one mapper can be used per project. All mappers expose `FIXED_SLOT`, `PAGE_

Before accessing data from the page slots (e.g. when loading an asset) remember to first tell the mapper to 'page' to the bank you want to access. You can use WLA-DX's colon prefix for a label to retrieve the bank number it has been placed in.

```
```asm
mapper.pageBank :paletteData ; ensure the bank containing paletteData is accessible
palette.writeSlice paletteData, 1 ; you can now use paletteData
``
```

### Page Slot B

Some mappers also provide a second pageable slot, `PAGE_SLOT_B`. It's generally simpler to stick to the one (`PAGE_SLOT_A`) but if you happened to have an asset over 16KB in size then both page slots could be used together to map the whole asset at once.

```
```asm
; Asset intended to be mapped into mapper.PAGE_SLOT_B
.slot mapper.PAGE_SLOT_B
paletteData:
Expand All @@ -62,7 +62,7 @@ palette.writeSlice paletteData, 1 ; palette data now accessible

You can customise some mappers with additional parameters. Check the relevant mapper asm file to see which settings are supported.

```
```asm
.define mapper.PAGEABLE_BANKS 4
.define mapper.ENABLE_CARTRIDGE_RAM 1
.include "smslib/mapper/sega.asm"
Expand Down
12 changes: 6 additions & 6 deletions docs/palette.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To get you started you can call `palette.rgb` with some RGB values to generate a

Each color component can have the value of 0, 85, 170 or 255. Values inbetween these will be rounded to the closest factor.

```
```asm
paletteData:
palette.rgb 255, 0, 0 ; red
palette.rgb 255, 170, 0 ; orange
Expand All @@ -35,7 +35,7 @@ You can then write these into the VDP VRAM the following macros.

Set the color palette index ready to write to:

```
```asm
palette.setIndex 0 ; set the first color index
palette.setIndex palette.SPRITE_PALETTE ; first color in 'sprite' palette
palette.setIndex palette.SPRITE_PALETTE + 1 ; second color in 'sprite' palette
Expand All @@ -44,7 +44,7 @@ palette.setIndex palette.SPRITE_PALETTE + 1 ; second color in 'sprite' palette

Write bytes of raw data to the color RAM:

```
```asm
myPaletteData:
.incbin "myPalette.inc" fsize myPaletteDataSize
Expand All @@ -56,15 +56,15 @@ palette.writeBytes myPaletteData, myPaletteDataSize

Write specific colors from the data.

```
```asm
palette.setIndex 0 ; point to first palette index
palette.writeSlice paletteData, 3 ; write 3 colors from current index onwards (indices 0, 1, 2)
palette.writeSlice otherPaletteData, 2; write 2 more colors (indices 3 and 4)
```

An optional third parameter lets you skip some colors in the data:

```
```asm
; Load 5 colors but skip the first 2
palette.writeSlice paletteData, 5, 2
```
Expand All @@ -73,7 +73,7 @@ palette.writeSlice paletteData, 5, 2

Loads an approximate RGB value into the current palette index. Each component is rounded to the nearest of the following values: 0, 85, 170, 255.

```
```asm
palette.setIndex 0
palette.writeRgb 255, 0, 0 ; a bright red
```
6 changes: 3 additions & 3 deletions docs/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Writes uncompressed pattern data into VRAM.

Due to WLA-DX limitations the size parameter must be an `immediate` value, so cannot be calculated using something like `endAddr - startAddr`. It can therefore either be a constant, or if using `fsize` to calculate the size of an included binary you just have to ensure this label is defined before this macro is called.

```
```asm
uncompressedPatternData:
.incbin "tiles.bin" fsize patternDataSize
Expand All @@ -23,7 +23,7 @@ patterns.writeBytes uncompressedPatternData, patternDataSize

Lets you pick out certain tiles from the binary data and write them individually.

```
```asm
myUncompressedPatternData:
.incbin 'tiles.bin'
Expand All @@ -37,7 +37,7 @@ patterns.writeSlice myUncompressedPatternData, 1

An optional third parameter lets you skip a certain number of patterns in the data:

```
```asm
; Write another pattern, skipping the first 9
patterns.writeSlice otherPatternData, 1, 9
```
Expand Down
4 changes: 2 additions & 2 deletions docs/pause.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Provides a pause handler that toggles a flag in RAM whenever the pause button is

Basic pause functionality can be provided by simply waiting until the pause button is pressed again:

```
```asm
pause.waitIfPaused
```

If you wish to jp or call a label based on the pause state, you can use the following:

```
```asm
pause.jpIfPaused myPauseState
pause.callIfPaused myPauseState
Expand Down
Loading

0 comments on commit 3e00a3c

Please sign in to comment.