Skip to content

Commit

Permalink
Merge pull request #15 from sylr/fix-panic-large-screen
Browse files Browse the repository at this point in the history
Fix integer overflow panic on large display
  • Loading branch information
const-void authored Dec 15, 2024
2 parents b048107 + 342c47e commit e95b6d4
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ var bg: [MAX_COLOR][]u8 = undefined;

// cache fg/bg ansi codes
pub fn initColor() void {
var color_idx: u16 = 0;
var color_idx: u32 = 0;
while (color_idx < MAX_COLOR) : (color_idx += 1) {
fg[color_idx] = std.fmt.allocPrint(allocator, "{s}38;5;{d}m", .{ csi, color_idx }) catch unreachable;
bg[color_idx] = std.fmt.allocPrint(allocator, "{s}48;5;{d}m", .{ csi, color_idx }) catch unreachable;
Expand Down Expand Up @@ -369,7 +369,7 @@ pub fn showGrayscale() void {
var fg_idx: u8 = 15;
emit(fg[fg_idx]);

var bg_idx: u16 = 232;
var bg_idx: u32 = 232;
while (bg_idx < 256) : (bg_idx += 1) {
if (bg_idx > 243) {
fg_idx = 0;
Expand Down Expand Up @@ -548,10 +548,10 @@ pub fn freeBuf() void {

pub fn showDoomFire() void {
//term size => fire size
const FIRE_H: u16 = @as(u16, @intCast(term_sz.height)) * 2;
const FIRE_W: u16 = @as(u16, @intCast(term_sz.width));
const FIRE_SZ: u16 = FIRE_H * FIRE_W;
const FIRE_LAST_ROW: u16 = (FIRE_H - 1) * FIRE_W;
const FIRE_H: u32 = @as(u32, @intCast(term_sz.height)) * 2;
const FIRE_W: u32 = @as(u32, @intCast(term_sz.width));
const FIRE_SZ: u32 = FIRE_H * FIRE_W;
const FIRE_LAST_ROW: u32 = (FIRE_H - 1) * FIRE_W;

//colors - tinker w/palette as needed!
const fire_palette = [_]u8{ 0, 233, 234, 52, 53, 88, 89, 94, 95, 96, 130, 131, 132, 133, 172, 214, 215, 220, 220, 221, 3, 226, 227, 230, 195, 230 };
Expand All @@ -564,7 +564,7 @@ pub fn showDoomFire() void {
defer allocator.free(screen_buf);

//init buffer
var buf_idx: u16 = 0;
var buf_idx: u32 = 0;
while (buf_idx < FIRE_SZ) : (buf_idx += 1) {
screen_buf[buf_idx] = fire_black;
}
Expand All @@ -583,22 +583,22 @@ pub fn showDoomFire() void {

//scope cache ////////////////////
//scope cache - update fire buf
var doFire_x: u16 = 0;
var doFire_y: u16 = 0;
var doFire_idx: u16 = 0;
var doFire_x: u32 = 0;
var doFire_y: u32 = 0;
var doFire_idx: u32 = 0;

//scope cache - spread fire
var spread_px: u8 = 0;
var spread_rnd_idx: u8 = 0;
var spread_dst: u16 = 0;
var spread_dst: u32 = 0;

//scope cache - frame reset
const init_frame = std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ cursor_home, bg[0], fg[0] }) catch unreachable;
defer allocator.free(init_frame);

//scope cache - fire 2 screen buffer
var frame_x: u16 = 0;
var frame_y: u16 = 0;
var frame_x: u32 = 0;
var frame_y: u32 = 0;
var px_hi: u8 = fire_black;
var px_lo: u8 = fire_black;
var px_prev_hi = px_hi;
Expand Down Expand Up @@ -711,7 +711,7 @@ const win32 = struct {
pub const CONSOLE_SCREEN_BUFFER_INFO = extern struct {
dwSize: COORD,
dwCursorPosition: COORD,
wAttributes: u16,
wAttributes: u32,
srWindow: SMALL_RECT,
dwMaximumWindowSize: COORD,
};
Expand Down

0 comments on commit e95b6d4

Please sign in to comment.